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

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


  }

  private List /* AnnotationGen */<AnnotationGen> makeMutableVersion(AnnotationGen[] mutableArray) {
    List<AnnotationGen> result = new ArrayList<AnnotationGen>();
    for (int i = 0; i < mutableArray.length; i++) {
      result.add(new AnnotationGen(mutableArray[i], getConstantPool(), false));
    }
    return result;
  }
View Full Code Here


        setValue(((ConstantValue) attrs[i]).getConstantValueIndex());
      } else if (attrs[i] instanceof RuntimeAnnos) {
        RuntimeAnnos runtimeAnnotations = (RuntimeAnnos) attrs[i];
        List<AnnotationGen> l = runtimeAnnotations.getAnnotations();
        for (Iterator<AnnotationGen> it = l.iterator(); it.hasNext();) {
          AnnotationGen element = it.next();
          addAnnotation(new AnnotationGen(element, cp, false));
        }
      } else {
        addAttribute(attrs[i]);
      }
    }
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.EMPTY_LIST,
          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);
        cg.addField(field, null);
View Full Code Here

      gen.addAttribute(attr);
    }

    if (newAnnotations != null) {
      for (AnnotationAJ element : newAnnotations) {
        gen.addAnnotation(new AnnotationGen(((BcelAnnotation) element).getBcelAnnotation(), gen.getConstantPool(), true));
      }
    }

    if (newParameterAnnotations != null) {
      for (int i = 0; i < newParameterAnnotations.length; i++) {
        AnnotationAJ[] annos = newParameterAnnotations[i];
        for (int j = 0; j < annos.length; j++) {
          gen.addParameterAnnotation(i,
              new AnnotationGen(((BcelAnnotation) annos[j]).getBcelAnnotation(), gen.getConstantPool(), true));
        }
      }
    }

    if (memberView != null && memberView.getAnnotations() != null && memberView.getAnnotations().length != 0) {
      AnnotationAJ[] ans = memberView.getAnnotations();
      for (int i = 0, len = ans.length; i < len; i++) {
        AnnotationGen a = ((BcelAnnotation) ans[i]).getBcelAnnotation();
        gen.addAnnotation(new AnnotationGen(a, gen.getConstantPool(), true));
      }
    }

    if (isSynthetic) {
      if (enclosingClass.getWorld().isInJava5Mode()) {
View Full Code Here

          annotationsOnRealMember = realMember.getAnnotations();
        }
        Set<ResolvedType> addedAnnotations = new HashSet<ResolvedType>();
        if (annotationsOnRealMember != null) {
          for (AnnotationAJ anno : annotationsOnRealMember) {
            AnnotationGen a = ((BcelAnnotation) anno).getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a, classGen.getConstantPool(), true);
            newMethod.addAnnotation(new BcelAnnotation(ag, classWeaver.getWorld()));
            addedAnnotations.add(anno.getType());
          }
        }
        if (realMember != null) {
          copyOverParameterAnnotations(newMethod, realMember);
        }
        // the code below was originally added to cope with the case where an aspect declares an annotation on an ITD
        // declared within itself (an unusual situation). However, it also addresses the case where we may not find the
        // annotation on the real representation of the ITD. This can happen in a load-time weaving situation where
        // we couldn't add the annotation in time - and so here we recheck the declare annotations. Not quite ideal but
        // works. pr288635
        List<DeclareAnnotation> allDecams = world.getDeclareAnnotationOnMethods();
        for (DeclareAnnotation declareAnnotationMC : allDecams) {
          if (declareAnnotationMC.matches(unMangledInterMethod, world)) {
            // && newMethod.getEnclosingClass().getType() == aspectType) {
            AnnotationAJ annotation = declareAnnotationMC.getAnnotation();
            if (!addedAnnotations.contains(annotation.getType())) {
              newMethod.addAnnotation(annotation);
            }
          }
        }
      }

      // If it doesn't target an interface and there is a body (i.e. it
      // isnt abstract)
      if (!onInterface && !Modifier.isAbstract(mangledInterMethod.getModifiers())) {
        InstructionList body = newMethod.getBody();
        InstructionFactory fact = classGen.getFactory();
        int pos = 0;

        if (!Modifier.isStatic(unMangledInterMethod.getModifiers())) {
          body.append(InstructionFactory.createThis());
          pos++;
        }
        Type[] paramTypes = BcelWorld.makeBcelTypes(mangledInterMethod.getParameterTypes());
        for (int i = 0, len = paramTypes.length; i < len; i++) {
          Type paramType = paramTypes[i];
          body.append(InstructionFactory.createLoad(paramType, pos));
          pos += paramType.getSize();
        }
        body.append(Utility.createInvoke(fact, classWeaver.getWorld(), interMethodBody));
        body.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(mangledInterMethod.getReturnType())));

        if (classWeaver.getWorld().isInJava5Mode()) { // Don't need bridge
          // methods if not in
          // 1.5 mode.
          createAnyBridgeMethodsForCovariance(classWeaver, munger, unMangledInterMethod, onType, classGen, paramTypes);
        }

      } else {
        // ??? this is okay
        // if (!(mg.getBody() == null)) throw new
        // RuntimeException("bas");
      }

      if (world.isInJava5Mode()) {
        String basicSignature = mangledInterMethod.getSignature();
        String genericSignature = ((ResolvedMemberImpl) mangledInterMethod).getSignatureForAttribute();
        if (!basicSignature.equals(genericSignature)) {
          // Add a signature attribute to it
          newMethod.addAttribute(createSignatureAttribute(classGen.getConstantPool(), genericSignature));
        }
      }
      // XXX make sure to check that we set exceptions properly on this
      // guy.
      classWeaver.addLazyMethodGen(newMethod);
      classWeaver.getLazyClassGen().warnOnAddedMethod(newMethod.getMethod(), getSignature().getSourceLocation());

      addNeededSuperCallMethods(classWeaver, onType, munger.getSuperMethodsCalled());

      return true;

    } else if (onInterface && !Modifier.isAbstract(unMangledInterMethod.getModifiers())) {

      // This means the 'gen' should be the top most implementor
      // - if it is *not* then something went wrong after we worked
      // out that it was the top most implementor (see pr49657)
      if (!classGen.getType().isTopmostImplementor(onType)) {
        ResolvedType rtx = classGen.getType().getTopmostImplementor(onType);
        if (rtx == null) {
          // pr302460
          // null means there is something wrong with what we are looking at
          ResolvedType rt = classGen.getType();
          if (rt.isInterface()) {
            ISourceLocation sloc = munger.getSourceLocation();
            classWeaver
                .getWorld()
                .getMessageHandler()
                .handleMessage(
                    MessageUtil.error(
                        "ITD target "
                            + rt.getName()
                            + " is an interface but has been incorrectly determined to be the topmost implementor of "
                            + onType.getName() + ". ITD is " + this.getSignature(), sloc));
          }
          if (!onType.isAssignableFrom(rt)) {
            ISourceLocation sloc = munger.getSourceLocation();
            classWeaver
                .getWorld()
                .getMessageHandler()
                .handleMessage(
                    MessageUtil.error(
                        "ITD target " + rt.getName() + " doesn't appear to implement " + onType.getName()
                            + " why did we consider it the top most implementor? ITD is "
                            + this.getSignature(), sloc));
          }
        } else if (!rtx.isExposedToWeaver()) {
          ISourceLocation sLoc = munger.getSourceLocation();
          classWeaver
              .getWorld()
              .getMessageHandler()
              .handleMessage(
                  MessageUtil.error(WeaverMessages.format(WeaverMessages.ITD_NON_EXPOSED_IMPLEMENTOR, rtx,
                      getAspectType().getName()), (sLoc == null ? getAspectType().getSourceLocation() : sLoc)));
        } else {
          // XXX what does this state mean?
          // We have incorrectly identified what is the top most
          // implementor and its not because
          // a type wasn't exposed to the weaver
        }
        return false;
      } else {

        ResolvedMember mangledInterMethod = AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, false);

        LazyMethodGen mg = makeMethodGen(classGen, mangledInterMethod);

        // From 98901#29 - need to copy annotations across
        if (classWeaver.getWorld().isInJava5Mode()) {
          AnnotationAJ annotationsOnRealMember[] = null;
          ResolvedType toLookOn = aspectType;
          if (aspectType.isRawType()) {
            toLookOn = aspectType.getGenericType();
          }
          ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn, memberHoldingAnyAnnotations, false);
          if (realMember == null) {
            throw new BCException("Couldn't find ITD holder member '" + memberHoldingAnyAnnotations + "' on aspect "
                + aspectType);
          }
          annotationsOnRealMember = realMember.getAnnotations();

          if (annotationsOnRealMember != null) {
            for (AnnotationAJ annotationX : annotationsOnRealMember) {
              AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
              AnnotationGen ag = new AnnotationGen(a, classWeaver.getLazyClassGen().getConstantPool(), true);
              mg.addAnnotation(new BcelAnnotation(ag, classWeaver.getWorld()));
            }
          }

          copyOverParameterAnnotations(mg, realMember);
View Full Code Here

            break;
          }
        }
        if (annotationsOnRealMember != null) {
          for (AnnotationAJ anno : annotationsOnRealMember) {
            AnnotationGen a = ((BcelAnnotation) anno).getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
            mg.addAnnotation(new BcelAnnotation(ag, weaver.getWorld()));
          }
        }
      }
View Full Code Here

        annotationsOnRealMember = realMember.getAnnotations();
      }
      if (annotationsOnRealMember != null) {
        for (int i = 0; i < annotationsOnRealMember.length; i++) {
          AnnotationAJ annotationX = annotationsOnRealMember[i];
          AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
          AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
          mg.addAnnotation(new BcelAnnotation(ag, weaver.getWorld()));
        }
      }
      // the below loop fixes the very special (and very stupid)
      // case where an aspect declares an annotation
View Full Code Here

        FieldGen fg = makeFieldGen(gen, newField);

        if (annotationsOnRealMember != null) {
          for (int i = 0; i < annotationsOnRealMember.length; i++) {
            AnnotationAJ annotationX = annotationsOnRealMember[i];
            AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
            AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
            fg.addAnnotation(ag);
          }
        }

        if (weaver.getWorld().isInJava5Mode()) {
          String basicSignature = field.getSignature();
          String genericSignature = field.getReturnType().resolve(weaver.getWorld()).getSignatureForAttribute();
          // String genericSignature =
          // ((ResolvedMemberImpl)field).getSignatureForAttribute();
          if (!basicSignature.equals(genericSignature)) {
            // Add a signature attribute to it
            fg.addAttribute(createSignatureAttribute(gen.getConstantPool(), genericSignature));
          }
        }
        gen.addField(fg, getSourceLocation());

      }
      return true;
    } else if (onInterface && gen.getType().isTopmostImplementor(onType)) {
      // wew know that we can't be static since we don't allow statics on
      // interfaces
      if (Modifier.isStatic(field.getModifiers())) {
        throw new RuntimeException("unimplemented");
      }
      weaver.addInitializer(this);
      // System.err.println("impl body on " + gen.getType() + " for " +
      // munger);

      Type fieldType = BcelWorld.makeBcelType(field.getType());

      FieldGen fg = makeFieldGen(gen, AjcMemberMaker.interFieldInterfaceField(field, onType, aspectType));

      if (annotationsOnRealMember != null) {
        for (int i = 0; i < annotationsOnRealMember.length; i++) {
          AnnotationAJ annotationX = annotationsOnRealMember[i];
          AnnotationGen a = ((BcelAnnotation) annotationX).getBcelAnnotation();
          AnnotationGen ag = new AnnotationGen(a, weaver.getLazyClassGen().getConstantPool(), true);
          fg.addAnnotation(ag);
        }
      }

      gen.addField(fg, getSourceLocation());
View Full Code Here

    // So we have an entity that has an annotation on and within it is the
    // value we want
    Member holder = annoAccessor.getMember();
    AnnotationAJ[] annos = holder.getAnnotations();
    for (int i = 0; i < annos.length; i++) {
      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)) {
            // il.append(fact.createGetStatic(rt.getName(), v.getEnumValueString(), Type.getType(rt.getSignature())));
            // doneAndDusted = true;
            // }
          }
        }
        if (!doneAndDusted) {
          ResolvedMember[] annotationFields = toType.getWorld()
              .resolve(UnresolvedType.forSignature(annotation.getTypeSignature())).getDeclaredMethods();

          // ResolvedMember[] fs = rt.getDeclaredFields();
          for (int ii = 0; ii < annotationFields.length; ii++) {
            if (annotationFields[ii].getType().equals(annoFieldOfInterest)) {
              String dvalue = annotationFields[ii].getAnnotationDefaultValue();
View Full Code Here

   * @param runtimeAnnotations
   * @param struct
   * @return true if found
   */
  private static boolean handleAspectAnnotation(RuntimeAnnos runtimeAnnotations, AjAttributeStruct struct) {
    AnnotationGen aspect = getAnnotation(runtimeAnnotations, AjcMemberMaker.ASPECT_ANNOTATION);
    if (aspect != null) {
      // semantic check for inheritance (only one level up)
      boolean extendsAspect = false;
      if (!"java.lang.Object".equals(struct.enclosingType.getSuperclass().getName())) {
        if (!struct.enclosingType.getSuperclass().isAbstract() && struct.enclosingType.getSuperclass().isAspect()) {
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.