Package org.aspectj.weaver

Examples of org.aspectj.weaver.AnnotationAJ


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


      if (onType.hasAnnotation(decA.getAnnotation().getType())) {
        // already has it
        return false;
      }

      AnnotationAJ annoX = decA.getAnnotation();

      // check the annotation is suitable for the target
      boolean isOK = checkTargetOK(decA, onType, annoX);

      if (isOK) {
View Full Code Here

      // pr98901
      // For copying the annotations across, we have to discover the real
      // member in the aspect which is holding them.
      if (classWeaver.getWorld().isInJava5Mode()) {
        AnnotationAJ annotationsOnRealMember[] = null;
        ResolvedType toLookOn = aspectType;
        if (aspectType.isRawType()) {
          toLookOn = aspectType.getGenericType();
        }
        ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn, memberHoldingAnyAnnotations, false);
        // 266602 - consider it missing to mean that the corresponding aspect had errors
        if (realMember == null) {
          // signalWarning("Unable to apply any annotations attached to " + munger.getSignature(), weaver);
          // throw new BCException("Couldn't find ITD init member '" + interMethodBody + "' on aspect " + aspectType);
        } else {
          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);
View Full Code Here

          introduced.getName(), BcelWorld.makeBcelTypes(introduced.getParameterTypes()),
          BcelWorld.makeBcelTypesAsClassNames(introduced.getExceptions()), gen);

      // annotation copy from annotation on ITD interface
      if (weaver.getWorld().isInJava5Mode()) {
        AnnotationAJ annotationsOnRealMember[] = null;
        ResolvedType toLookOn = weaver.getWorld().lookupOrCreateName(introduced.getDeclaringType());
        if (fromType.isRawType()) {
          toLookOn = fromType.getGenericType();
        }
        // lookup the method
View Full Code Here

    // which is holding them.
    if (weaver.getWorld().isInJava5Mode()) {

      ResolvedMember interMethodDispatcher = AjcMemberMaker.postIntroducedConstructor(aspectType, onType,
          newConstructorTypeMunger.getSignature().getParameterTypes());
      AnnotationAJ annotationsOnRealMember[] = null;
      ResolvedMember realMember = getRealMemberForITDFromAspect(aspectType, interMethodDispatcher, true);
      // 266602 - consider it missing to mean that the corresponding aspect had errors
      if (realMember == null) {
        // signalWarning("Unable to apply any annotations attached to " + munger.getSignature(), weaver);
        // throw new BCException("Couldn't find ITD init member '" + interMethodBody + "' on aspect " + aspectType);
      } else {
        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()));
        }
      }
View Full Code Here

      return false;
    }

    ResolvedMember interMethodBody = munger.getInitMethod(aspectType);

    AnnotationAJ annotationsOnRealMember[] = null;
    // pr98901
    // For copying the annotations across, we have to discover the real
    // member in the aspect
    // which is holding them.
    if (weaver.getWorld().isInJava5Mode()) {
      // the below line just gets the method with the same name in
      // aspectType.getDeclaredMethods();
      ResolvedType toLookOn = aspectType;
      if (aspectType.isRawType()) {
        toLookOn = aspectType.getGenericType();
      }
      ResolvedMember realMember = getRealMemberForITDFromAspect(toLookOn, interMethodBody, false);
      if (realMember == null) {
        // signalWarning("Unable to apply any annotations attached to " + munger.getSignature(), weaver);
        // throw new BCException("Couldn't find ITD init member '" + interMethodBody + "' on aspect " + aspectType);
      } else {
        annotationsOnRealMember = realMember.getAnnotations();
      }
    }

    if (onType.equals(gen.getType())) {
      if (onInterface) {
        ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, onType, aspectType);
        LazyMethodGen mg = makeMethodGen(gen, itdfieldGetter);
        gen.addMethodGen(mg);

        LazyMethodGen mg1 = makeMethodGen(gen, AjcMemberMaker.interFieldInterfaceSetter(field, onType, aspectType));
        gen.addMethodGen(mg1);
      } else {
        weaver.addInitializer(this);
        ResolvedMember newField = AjcMemberMaker.interFieldClassField(field, aspectType,
            munger.version == NewFieldTypeMunger.VersionTwo);
        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);
        }
      }
View Full Code Here

            if (decaf.getAnnotation() == null) {
              return false;
            }
            if (decaf.matches(field, world)) {
              if (decaf.isRemover()) {
                AnnotationAJ annotation = decaf.getAnnotation();
                if (field.hasAnnotation(annotation.getType())) {
                  // something to remove
                  typeIsChanged = true;
                  field.removeAnnotation(annotation);
                  AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
                      decaf.getSourceLocation(), clazz.getName(), field, true);
                  reportFieldAnnotationWeavingMessage(clazz, field, decaf, true);
                } else {
                  worthRetrying.add(decaf);
                }
                unusedDecafs.remove(decaf);
              } else {
                if (!dontAddTwice(decaf, dontAddMeTwice)) {
                  if (doesAlreadyHaveAnnotation(field, decaf, reportedProblems)) {
                    // remove the declare @field since don't want an error when the annotation is already there
                    unusedDecafs.remove(decaf);
                    continue;
                  }
                  field.addAnnotation(decaf.getAnnotation());
                }
                AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
                    decaf.getSourceLocation(), clazz.getName(), field, false);
                reportFieldAnnotationWeavingMessage(clazz, field, decaf, false);
                typeIsChanged = true;
                modificationOccured = true;
                unusedDecafs.remove(decaf);
              }
            } else if (!decaf.isStarredAnnotationPattern() || decaf.isRemover()) {
              worthRetrying.add(decaf); // 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 with any remaining ones
            List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>();
            for (Iterator<DeclareAnnotation> iter = worthRetrying.iterator(); iter.hasNext();) {
              DeclareAnnotation decaF = iter.next();

              if (decaF.matches(field, world)) {
                if (decaF.isRemover()) {
                  AnnotationAJ annotation = decaF.getAnnotation();
                  if (field.hasAnnotation(annotation.getType())) {
                    // something to remove
                    typeIsChanged = modificationOccured = true;
                    forRemoval.add(decaF);
                    field.removeAnnotation(annotation);
                    AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
View Full Code Here

          }
        }

        // Are we also matching annotation values?
        if (annotationValues != null) {
          AnnotationAJ theAnnotation = annotated.getAnnotationOfType(annotationType);

          // Check each one
          Set<String> keys = annotationValues.keySet();
          for (String k : keys) {
            String v = annotationValues.get(k);
            if (theAnnotation.hasNamedValue(k)) {
              // Simple case, value is 'name=value' and the
              // annotation specified the same thing
              if (!theAnnotation.hasNameValuePair(k, v)) {
                return FuzzyBoolean.NO;
              }
            } else {
              // Complex case, look at the default value
              ResolvedMember[] ms = ((ResolvedType) annotationType).getDeclaredMethods();
              boolean foundMatch = false;
              for (int i = 0; i < ms.length && !foundMatch; i++) {
                if (ms[i].isAbstract() && ms[i].getParameterTypes().length == 0 && ms[i].getName().equals(k)) {
                  // we might be onto something
                  String s = ms[i].getAnnotationDefaultValue();
                  if (s != null && s.equals(v)) {
                    foundMatch = true;
                  }
                }
              }
              if (!foundMatch) {
                return FuzzyBoolean.NO;
              }
            }
          }
        }
        return FuzzyBoolean.YES;
      } else if (checkSupers) {
        ResolvedType toMatchAgainst = ((ResolvedType) annotated).getSuperclass();
        while (toMatchAgainst != null) {
          if (toMatchAgainst.hasAnnotation(annotationType)) {
            // Are we also matching annotation values?
            if (annotationValues != null) {
              AnnotationAJ theAnnotation = toMatchAgainst.getAnnotationOfType(annotationType);

              // Check each one
              Set<String> keys = annotationValues.keySet();
              for (String k : keys) {
                String v = annotationValues.get(k);
                if (theAnnotation.hasNamedValue(k)) {
                  // Simple case, value is 'name=value' and
                  // the annotation specified the same thing
                  if (!theAnnotation.hasNameValuePair(k, v)) {
                    return FuzzyBoolean.NO;
                  }
                } else {
                  // Complex case, look at the default value
                  ResolvedMember[] ms = ((ResolvedType) annotationType).getDeclaredMethods();
View Full Code Here

   * Apply a declare @type - return true if we change the type
   */
  private boolean applyDeclareAtType(DeclareAnnotation decA, ResolvedType onType, boolean reportProblems) {
    boolean didSomething = false;
    if (decA.matches(onType)) {
      AnnotationAJ theAnnotation = decA.getAnnotation();
      // can be null for broken code!
      if (theAnnotation == null) {
        return false;
      }
      if (onType.hasAnnotation(theAnnotation.getType())) {
        // Could put out a lint here for an already annotated type ...
        // if (reportProblems) {
        // world.getLint().elementAlreadyAnnotated.signal(
        // new
        // String[]{onType.toString(),decA.getAnnotationTypeX().toString
        // ()},
        // onType.getSourceLocation(),new
        // ISourceLocation[]{decA.getSourceLocation()});
        // }
        return false;
      }

      AnnotationAJ annoX = decA.getAnnotation();

      // check the annotation is suitable for the target
      boolean problemReported = verifyTargetIsOK(decA, onType, annoX, reportProblems);

      if (!problemReported) {
View Full Code Here

            if (decaf.getAnnotation() == null) {
              return false;
            }
            if (decaf.matches(field, world)) {
              if (decaf.isRemover()) {
                AnnotationAJ annotation = decaf.getAnnotation();
                if (field.hasAnnotation(annotation.getType())) {
                  // something to remove
                  typeIsChanged = true;
                  field.removeAnnotation(annotation);
                  AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
                      decaf.getSourceLocation(), clazz.getName(), field, true);
                  reportFieldAnnotationWeavingMessage(clazz, field, decaf, true);
                } else {
                  worthRetrying.add(decaf);
                }
                unusedDecafs.remove(decaf);
              } else {
                if (!dontAddTwice(decaf, dontAddMeTwice)) {
                  if (doesAlreadyHaveAnnotation(field, decaf, reportedProblems)) {
                    // remove the declare @field since don't want an error when the annotation is already there
                    unusedDecafs.remove(decaf);
                    continue;
                  }
                  field.addAnnotation(decaf.getAnnotation());
                }
                AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
                    decaf.getSourceLocation(), clazz.getName(), field, false);
                reportFieldAnnotationWeavingMessage(clazz, field, decaf, false);
                typeIsChanged = true;
                modificationOccured = true;
                unusedDecafs.remove(decaf);
              }
            } else if (!decaf.isStarredAnnotationPattern() || decaf.isRemover()) {
              worthRetrying.add(decaf); // 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 with any remaining ones
            List<DeclareAnnotation> forRemoval = new ArrayList<DeclareAnnotation>();
            for (Iterator<DeclareAnnotation> iter = worthRetrying.iterator(); iter.hasNext();) {
              DeclareAnnotation decaF = iter.next();

              if (decaF.matches(field, world)) {
                if (decaF.isRemover()) {
                  AnnotationAJ annotation = decaF.getAnnotation();
                  if (field.hasAnnotation(annotation.getType())) {
                    // something to remove
                    typeIsChanged = modificationOccured = true;
                    forRemoval.add(decaF);
                    field.removeAnnotation(annotation);
                    AsmRelationshipProvider.addDeclareAnnotationFieldRelationship(world.getModelAsAsmManager(),
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.AnnotationAJ

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.