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

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


            alreadyHasIt = true;
            break;
          }
        }
        if (!alreadyHasIt) {
          fg.addAnnotation(new AnnotationGen(((BcelAnnotation) array_element).getBcelAnnotation(), cpg, true));
        }
      }
    }
    field = fg.getField();
    annotationsAdded = false; // we are now correct again
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

    }
    if ((bitflags & HAVE_DETERMINED_ANNOTATIONS) != 0) {
      return;
    }
    bitflags |= HAVE_DETERMINED_ANNOTATIONS;
    AnnotationGen annos[] = method.getAnnotations();
    if (annos.length == 0) {
      annotationTypes = ResolvedType.NONE;
      annotations = AnnotationAJ.EMPTY_ARRAY;
    } else {
      int annoCount = annos.length;
      annotationTypes = new ResolvedType[annoCount];
      annotations = new AnnotationAJ[annoCount];
      for (int i = 0; i < annoCount; i++) {
        AnnotationGen annotation = annos[i];
        annotations[i] = new BcelAnnotation(annotation, bcelObjectType.getWorld());
        annotationTypes[i] = annotations[i].getType();
      }
      bitflags |= HAS_ANNOTATIONS;
    }
View Full Code Here

    if (parameterAnnotationTypes == null || pAnns.length != parameterAnnotationTypes.length) {
      if (pAnns == Method.NO_PARAMETER_ANNOTATIONS) {
        parameterAnnotationTypes = BcelMethod.NO_PARAMETER_ANNOTATION_TYPES;
        parameterAnnotations = BcelMethod.NO_PARAMETER_ANNOTATIONXS;
      } else {
        AnnotationGen annos[][] = method.getParameterAnnotations();
        parameterAnnotations = new AnnotationAJ[annos.length][];
        parameterAnnotationTypes = new ResolvedType[annos.length][];
        for (int i = 0; i < annos.length; i++) {
          AnnotationGen[] annosOnThisParam = annos[i];
          if (annos[i].length == 0) {
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

        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

          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

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.