Package org.aspectj.weaver

Examples of org.aspectj.weaver.ResolvedType$Primitive


  private boolean mungePrivilegedAccess(BcelClassWeaver weaver, PrivilegedAccessMunger munger) {
    LazyClassGen gen = weaver.getLazyClassGen();
    ResolvedMember member = munger.getMember();

    ResolvedType onType = weaver.getWorld().resolve(member.getDeclaringType(), munger.getSourceLocation());
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }

    // System.out.println("munging: " + gen + " with " + member);
    if (onType.equals(gen.getType())) {
      if (member.getKind() == Member.FIELD) {
        // System.out.println("matched: " + gen);
        addFieldGetter(gen, member,
            AjcMemberMaker.privilegedAccessMethodForFieldGet(aspectType, member, munger.shortSyntax));
        addFieldSetter(gen, member,
View Full Code Here


    return !bcelObjectType.isInterface();
  }

  private boolean mungeNewMemberType(BcelClassWeaver classWeaver, NewMemberClassTypeMunger munger) {
    World world = classWeaver.getWorld();
    ResolvedType onType = world.resolve(munger.getTargetType());
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }
    return onType.equals(classWeaver.getLazyClassGen().getType());
  }
View Full Code Here

    ResolvedMember interMethodBody = munger.getDeclaredInterMethodBody(aspectType, world);
    ResolvedMember interMethodDispatcher = munger.getDeclaredInterMethodDispatcher(aspectType, world);
    ResolvedMember memberHoldingAnyAnnotations = interMethodDispatcher;
    LazyClassGen classGen = classWeaver.getLazyClassGen();

    ResolvedType onType = world.resolve(unMangledInterMethod.getDeclaringType(), munger.getSourceLocation());
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }

    // Simple checks, can't ITD on annotations or enums
    if (onType.isAnnotation()) {
      signalError(WeaverMessages.ITDM_ON_ANNOTATION_NOT_ALLOWED, classWeaver, onType);
      return false;
    }

    if (onType.isEnum()) {
      signalError(WeaverMessages.ITDM_ON_ENUM_NOT_ALLOWED, classWeaver, onType);
      return false;
    }

    boolean mungingInterface = classGen.isInterface();
    boolean onInterface = onType.isInterface();

    if (onInterface
        && classGen.getLazyMethodGen(unMangledInterMethod.getName(), unMangledInterMethod.getSignature(), true) != null) {
      // this is ok, we could be providing the default implementation of a
      // method
      // that the target has already declared
      return false;
    }

    // If we are processing the intended ITD target type (might be an interface)
    if (onType.equals(classGen.getType())) {
      ResolvedMember mangledInterMethod = AjcMemberMaker.interMethod(unMangledInterMethod, aspectType, onInterface);

      LazyMethodGen newMethod = makeMethodGen(classGen, mangledInterMethod);
      if (mungingInterface) {
        // we want the modifiers of the ITD to be used for all *implementors* of the
        // interface, but the method itself we add to the interface must be public abstract
        newMethod.setAccessFlags(Modifier.PUBLIC | Modifier.ABSTRACT);
      }

      // 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);
          if (realMember == null) {
View Full Code Here

      return false;
    }

    ResolvedMember introduced = munger.getSignature();

    ResolvedType fromType = world.resolve(introduced.getDeclaringType(), munger.getSourceLocation());
    if (fromType.isRawType()) {
      fromType = fromType.getGenericType();
    }

    boolean shouldApply = munger.matches(weaver.getLazyClassGen().getType(), aspectType);

    if (shouldApply) {
      Type bcelReturnType = BcelWorld.makeBcelType(introduced.getReturnType());

      // If no implementation class was specified, the intention was that
      // the types matching the pattern
      // already implemented the interface, let's check that now!
      if (munger.getImplClassName() == null && !munger.specifiesDelegateFactoryMethod()) {
        boolean isOK = false;
        List<LazyMethodGen> existingMethods = gen.getMethodGens();
        for (LazyMethodGen m : existingMethods) {
          if (m.getName().equals(introduced.getName())
              && m.getParameterSignature().equals(introduced.getParameterSignature())
              && m.getReturnType().equals(bcelReturnType)) {
            isOK = true;
          }
        }
        if (!isOK) {
          // the class does not implement this method, they needed to
          // supply a default impl class
          IMessage msg = new Message("@DeclareParents: No defaultImpl was specified but the type '" + gen.getName()
              + "' does not implement the method '" + stringifyMember(introduced) + "' defined on the interface '"
              + introduced.getDeclaringType() + "'", weaver.getLazyClassGen().getType().getSourceLocation(), true,
              new ISourceLocation[] { munger.getSourceLocation() });
          weaver.getWorld().getMessageHandler().handleMessage(msg);
          return false;
        }

        return true;
      }

      LazyMethodGen mg = new LazyMethodGen(introduced.getModifiers() - Modifier.ABSTRACT, bcelReturnType,
          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
        ResolvedMember[] ms = toLookOn.getDeclaredJavaMethods();
        for (ResolvedMember m : ms) {
          if (introduced.getName().equals(m.getName()) && introduced.getSignature().equals(m.getSignature())) {
            annotationsOnRealMember = m.getAnnotations();
            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()));
          }
        }
      }

      InstructionList body = new InstructionList();
      InstructionFactory fact = gen.getFactory();

      // getfield
      body.append(InstructionConstants.ALOAD_0);
      body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
      InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
      body.append(ifNonNull);

      // Create and store a new instance
      body.append(InstructionConstants.ALOAD_0); // 'this' is where we'll store the field value

      // TODO for non-static case, call aspectOf() then call the factory method on the retval
      // TODO decide whether the value can really be cached

      // locate the aspect and call the static method in it
      if (munger.specifiesDelegateFactoryMethod()) {
        ResolvedMember rm = munger.getDelegateFactoryMethod(weaver.getWorld());

        // Check the method parameter is compatible with the type of the instance to be passed
        if (rm.getArity() != 0) {
          ResolvedType parameterType = rm.getParameterTypes()[0].resolve(weaver.getWorld());
          if (!parameterType.isAssignableFrom(weaver.getLazyClassGen().getType())) {
            signalError("For mixin factory method '" + rm + "': Instance type '" + weaver.getLazyClassGen().getType()
                + "' is not compatible with factory parameter type '" + parameterType + "'", weaver);
            return false;
          }
        }
View Full Code Here

          // right one. If it is ctor related we need to check the
          // params all match, although
          // only the erasure.
          if (isCtorRelated) {
            for (int j = 0; j < memberParams.length && matchOK; j++) {
              ResolvedType pMember = memberParams[j].resolve(world);
              ResolvedType pLookingFor = lookingForParams[j].resolve(world);

              if (pMember.isTypeVariableReference()) {
                pMember = ((TypeVariableReference) pMember).getTypeVariable().getFirstBound().resolve(world);
              }
              if (pMember.isParameterizedType() || pMember.isGenericType()) {
                pMember = pMember.getRawType().resolve(aspectType.getWorld());
              }

              if (pLookingFor.isTypeVariableReference()) {
                pLookingFor = ((TypeVariableReference) pLookingFor).getTypeVariable().getFirstBound()
                    .resolve(world);
              }
              if (pLookingFor.isParameterizedType() || pLookingFor.isGenericType()) {
                pLookingFor = pLookingFor.getRawType().resolve(world);
              }

              if (debug) {
                System.err.println("Comparing parameter " + j + "   member=" + pMember + "   lookingFor="
                    + pLookingFor);
View Full Code Here

    final LazyClassGen currentClass = weaver.getLazyClassGen();
    final InstructionFactory fact = currentClass.getFactory();

    ResolvedMember newConstructorMember = newConstructorTypeMunger.getSyntheticConstructor();
    ResolvedType onType = newConstructorMember.getDeclaringType().resolve(weaver.getWorld());
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }

    if (onType.isAnnotation()) {
      signalError(WeaverMessages.ITDC_ON_ANNOTATION_NOT_ALLOWED, weaver, onType);
      return false;
    }

    if (onType.isEnum()) {
      signalError(WeaverMessages.ITDC_ON_ENUM_NOT_ALLOWED, weaver, onType);
      return false;
    }

    if (!onType.equals(currentClass.getType())) {
      return false;
    }

    ResolvedMember explicitConstructor = newConstructorTypeMunger.getExplicitConstructor();
    // int declaredParameterCount =
View Full Code Here

  private boolean mungeNewField(BcelClassWeaver weaver, NewFieldTypeMunger munger) {
    /* ResolvedMember initMethod = */munger.getInitMethod(aspectType);
    LazyClassGen gen = weaver.getLazyClassGen();
    ResolvedMember field = munger.getSignature();

    ResolvedType onType = weaver.getWorld().resolve(field.getDeclaringType(), munger.getSourceLocation());
    if (onType.isRawType()) {
      onType = onType.getGenericType();
    }

    boolean onInterface = onType.isInterface();

    if (onType.isAnnotation()) {
      signalError(WeaverMessages.ITDF_ON_ANNOTATION_NOT_ALLOWED, weaver, onType);
      return false;
    }

    if (onType.isEnum()) {
      signalError(WeaverMessages.ITDF_ON_ENUM_NOT_ALLOWED, weaver, onType);
      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) {
View Full Code Here

      return Collections.emptyList();
    }

    Collection<ResolvedType> ret = new ArrayList<ResolvedType>();
    World world = concreteAspect.getWorld();
    ResolvedType runtimeException = world.getCoreType(UnresolvedType.RUNTIME_EXCEPTION);
    ResolvedType error = world.getCoreType(UnresolvedType.ERROR);

    for (int i = 0, len = excs.length; i < len; i++) {
      ResolvedType t = world.resolve(excs[i], true);
      if (t.isMissing()) {
        world.getLint().cantFindType
            .signal(WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE, excs[i].getName()),
                getSourceLocation());
        // IMessage msg = new Message(
        // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_EXCEPTION_TYPE,excs[i].getName()),
View Full Code Here

    int ret = concreteAspect.getWorld().compareByPrecedence(concreteAspect, o.concreteAspect);
    if (ret != 0) {
      return ret;
    }

    ResolvedType declaringAspect = getDeclaringAspect().resolve(world);
    ResolvedType o_declaringAspect = o.getDeclaringAspect().resolve(world);

    if (declaringAspect == o_declaringAspect) {
      if (kind.isAfter() || o.kind.isAfter()) {
        return this.getStart() < o.getStart() ? -1 : +1;
      } else {
        return this.getStart() < o.getStart() ? +1 : -1;
      }
    } else if (declaringAspect.isAssignableFrom(o_declaringAspect)) {
      return -1;
    } else if (o_declaringAspect.isAssignableFrom(declaringAspect)) {
      return +1;
    } else {
      return 0;
    }
  }
View Full Code Here

   * annotation they were working with and this code can be enhanced to support it.
   */
  public static AnnotationAJ convertEclipseAnnotation(Annotation eclipseAnnotation, World w, EclipseFactory factory) {
    // TODO if it is sourcevisible, we shouldn't let it through!!!!!!!!!
    // testcase!
    ResolvedType annotationType = factory.fromTypeBindingToRTX(eclipseAnnotation.type.resolvedType);
    // long bs = (eclipseAnnotation.bits & TagBits.AnnotationRetentionMASK);
    boolean isRuntimeVisible = (eclipseAnnotation.bits & TagBits.AnnotationRetentionMASK) == TagBits.AnnotationRuntimeRetention;
    StandardAnnotation annotationAJ = new StandardAnnotation(annotationType, isRuntimeVisible);
    generateAnnotation(eclipseAnnotation, annotationAJ);
    return annotationAJ;
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.ResolvedType$Primitive

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.