Package org.aspectj.weaver

Examples of org.aspectj.weaver.World$AspectPrecedenceCalculator


  public PerClause concretize(ResolvedType inAspect) {
    PerSingleton ret = new PerSingleton();

    ret.copyLocationFrom(this);

    World world = inAspect.getWorld();

    ret.inAspect = inAspect;

    // ATAJ: add a munger to add the aspectOf(..) to the @AJ aspects
    if (inAspect.isAnnotationStyleAspect() && !inAspect.isAbstract()) {
      // TODO will those change be ok if we add a serializable aspect ?
      // dig:
      // "can't be Serializable/Cloneable unless -XserializableAspects"
      if (getKind() == SINGLETON) { // pr149560
        inAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().makePerClauseAspect(inAspect, getKind()));
      } else {
        inAspect.crosscuttingMembers.addLateTypeMunger(world.getWeavingSupport().makePerClauseAspect(inAspect, getKind()));
      }
    }

    // ATAJ inline around advice support
    if (inAspect.isAnnotationStyleAspect() && !inAspect.getWorld().isXnoInline()) {
      inAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().createAccessForInlineMunger(inAspect));
    }

    return ret;
  }
View Full Code Here


      }
    }
    entryBindings.copyContext(bindings);
    // System.out.println(this + " bindings: " + entryBindings);

    World world = inAspect.getWorld();

    Pointcut concreteEntry;

    ResolvedType concreteAspect = bindings.getConcreteAspect();

    CrosscuttingMembers xcut = concreteAspect.crosscuttingMembers;
    Collection<ShadowMunger> previousCflowEntries = xcut.getCflowEntries();

    entryBindings.pushEnclosingDefinition(CFLOW_MARKER);
    // This block concretizes the pointcut within the cflow pointcut
    try {
      concreteEntry = entry.concretize(inAspect, declaringType, entryBindings);
    } finally {
      entryBindings.popEnclosingDefinitition();
    }

    List<ShadowMunger> innerCflowEntries = new ArrayList<ShadowMunger>(xcut.getCflowEntries());
    innerCflowEntries.removeAll(previousCflowEntries);

    // Four routes of interest through this code (did I hear someone say
    // refactor??)
    // 1) no state in the cflow - we can use a counter *and* we have seen
    // this pointcut
    // before - so use the same counter as before.
    // 2) no state in the cflow - we can use a counter, but this is the
    // first time
    // we have seen this pointcut, so build the infrastructure.
    // 3) state in the cflow - we need to use a stack *and* we have seen
    // this pointcut
    // before - so share the stack.
    // 4) state in the cflow - we need to use a stack, but this is the first
    // time
    // we have seen this pointcut, so build the infrastructure.

    if (freeVars == null || freeVars.length == 0) { // No state, so don't
      // use a stack, use a
      // counter.
      ResolvedMember localCflowField = null;

      Object field = getCflowfield(xcut, concreteEntry, concreteAspect, "counter");

      // Check if we have already got a counter for this cflow pointcut
      if (field != null) {
        localCflowField = (ResolvedMember) field; // Use the one we
        // already have

      } else {

        // Create a counter field in the aspect
        localCflowField = new ResolvedMemberImpl(Member.FIELD, concreteAspect, Modifier.STATIC | Modifier.PUBLIC
            | Modifier.FINAL, NameMangler.cflowCounter(xcut), UnresolvedType.forName(NameMangler.CFLOW_COUNTER_TYPE)
            .getSignature());

        // Create type munger to add field to the aspect
        concreteAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport().makeCflowCounterFieldAdder(
            localCflowField));

        // Create shadow munger to push stuff onto the stack
        concreteAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makeCflowEntry(world, concreteEntry, isBelow,
            localCflowField, freeVars == null ? 0 : freeVars.length, innerCflowEntries, inAspect));

        putCflowfield(xcut, concreteEntry, concreteAspect, localCflowField, "counter"); // Remember
        // it
      }

      Pointcut ret = new ConcreteCflowPointcut(concreteAspect, localCflowField, null, true);
      ret.copyLocationFrom(this);
      return ret;
    } else {

      List slots = new ArrayList();

      for (int i = 0, len = freeVars.length; i < len; i++) {
        int freeVar = freeVars[i];

        // we don't need to keep state that isn't actually exposed to
        // advice
        // ??? this means that we will store some state that we won't
        // actually use, optimize this later
        if (!bindings.hasKey(freeVar)) {
          continue;
        }

        int formalIndex = bindings.get(freeVar);

        // We need to look in the right place for the type of the
        // formal. Suppose the advice looks like this:
        // before(String s): somePointcut(*,s)
        // where the first argument in somePointcut is of type Number
        // for free variable 0 we want to ask the pointcut for the type
        // of its first argument, if we only
        // ask the advice for the type of its first argument then we'll
        // get the wrong type (pr86903)

        ResolvedPointcutDefinition enclosingDef = bindings.peekEnclosingDefinition();
        ResolvedType formalType = null;

        // Is there a useful enclosing pointcut?
        if (enclosingDef != null && enclosingDef.getParameterTypes().length > 0) {
          formalType = enclosingDef.getParameterTypes()[freeVar].resolve(world);
        } else {
          formalType = bindings.getAdviceSignature().getParameterTypes()[formalIndex].resolve(world);
        }

        ConcreteCflowPointcut.Slot slot = new ConcreteCflowPointcut.Slot(formalIndex, formalType, i);
        slots.add(slot);
      }
      ResolvedMember localCflowField = null;
      Object field = getCflowfield(xcut, concreteEntry, concreteAspect, "stack");
      if (field != null) {
        localCflowField = (ResolvedMember) field;
      } else {

        localCflowField = new ResolvedMemberImpl(Member.FIELD, concreteAspect, Modifier.STATIC | Modifier.PUBLIC
            | Modifier.FINAL, NameMangler.cflowStack(xcut), UnresolvedType.forName(NameMangler.CFLOW_STACK_TYPE)
            .getSignature());
        // System.out.println("adding field to: " + inAspect + " field "
        // + cflowField);

        // add field and initializer to inAspect
        // XXX and then that info above needs to be mapped down here to
        // help with
        // XXX getting the exposed state right
        concreteAspect.crosscuttingMembers.addConcreteShadowMunger(Advice.makeCflowEntry(world, concreteEntry, isBelow,
            localCflowField, freeVars.length, innerCflowEntries, inAspect));

        concreteAspect.crosscuttingMembers.addTypeMunger(world.getWeavingSupport()
            .makeCflowStackFieldAdder(localCflowField));
        putCflowfield(xcut, concreteEntry, concreteAspect, localCflowField, "stack");
      }
      Pointcut ret = new ConcreteCflowPointcut(concreteAspect, localCflowField, slots, false);
      ret.copyLocationFrom(this);
View Full Code Here

    // no warnings for declare error/warning
    if (munger instanceof Checker) {
      return;
    }

    World world = shadow.getIWorld();

    // warning never needed if the declaring type is any
    UnresolvedType exactDeclaringType = signature.getDeclaringType().getExactType();

    ResolvedType shadowDeclaringType = shadow.getSignature().getDeclaringType().resolve(world);

    if (signature.getDeclaringType().isStar() || ResolvedType.isMissing(exactDeclaringType)
        || exactDeclaringType.resolve(world).isMissing()) {
      return;
    }

    // warning not needed if match type couldn't ever be the declaring type
    if (!shadowDeclaringType.isAssignableFrom(exactDeclaringType.resolve(world))) {
      return;
    }

    // if the method in the declaring type is *not* visible to the
    // exact declaring type then warning not needed.
    ResolvedMember rm = shadow.getSignature().resolve(world);
    // rm can be null in the case where we are binary weaving, and looking at a class with a call to a method in another class,
    // but because of class incompatibilities, the method does not exist on the target class anymore.
    // this will be reported elsewhere.
    if (rm == null) {
      return;
    }

    int shadowModifiers = rm.getModifiers();
    if (!ResolvedType.isVisible(shadowModifiers, shadowDeclaringType, exactDeclaringType.resolve(world))) {
      return;
    }

    if (!signature.getReturnType().matchesStatically(shadow.getSignature().getReturnType().resolve(world))) {
      // Covariance issue...
      // The reason we didn't match is that the type pattern for the pointcut (Car) doesn't match the
      // return type for the specific declaration at the shadow. (FastCar Sub.getCar())
      // XXX Put out another XLINT in this case?
      return;
    }
    // PR60015 - Don't report the warning if the declaring type is object and 'this' is an interface
    if (exactDeclaringType.resolve(world).isInterface() && shadowDeclaringType.equals(world.resolve("java.lang.Object"))) {
      return;
    }

    SignaturePattern nonConfusingPattern = new SignaturePattern(signature.getKind(), signature.getModifiers(),
        signature.getReturnType(), TypePattern.ANY, signature.getName(), signature.getParameterTypes(),
View Full Code Here

    }
    signature = signature.resolveBindings(scope, bindings);

    if (kind == Shadow.ConstructorExecution) { // Bug fix 60936
      if (signature.getDeclaringType() != null) {
        World world = scope.getWorld();
        UnresolvedType exactType = signature.getDeclaringType().getExactType();
        if (signature.getKind() == Member.CONSTRUCTOR && !ResolvedType.isMissing(exactType)
            && exactType.resolve(world).isInterface() && !signature.getDeclaringType().isIncludeSubtypes()) {
          world.getLint().noInterfaceCtorJoinpoint.signal(exactType.toString(), getSourceLocation());
        }
      }
    }

    // no parameterized types
View Full Code Here

  public static void appendConversion(InstructionList il, InstructionFactory fact, ResolvedType fromType, ResolvedType toType) {
    if (!toType.isConvertableFrom(fromType) && !fromType.isConvertableFrom(toType)) {
      throw new BCException("can't convert from " + fromType + " to " + toType);
    }
    // XXX I'm sure this test can be simpler but my brain hurts and this works
    World w = toType.getWorld();
    if (w == null) { // dbg349636
      throw new IllegalStateException("Debug349636: Unexpectedly found world null for type " + toType.getName());
    }

    if (!w.isInJava5Mode()) {
      if (toType.needsNoConversionFrom(fromType)) {
        return;
      }
    } else {
      if (toType.needsNoConversionFrom(fromType) && !(toType.isPrimitiveType() ^ fromType.isPrimitiveType())) {
View Full Code Here

      // No annotation found
      return false;
    }

    Method annotatedMethod = struct.method;
    World world = struct.enclosingType.getWorld();
    NameValuePair declareMixinPatternNameValuePair = getAnnotationElement(declareMixinAnnotation, VALUE);

    // declareMixinPattern could be of the form "Bar*" or "A || B" or "Foo+"
    String declareMixinPattern = declareMixinPatternNameValuePair.getValue().stringifyValue();
    TypePattern targetTypePattern = parseTypePattern(declareMixinPattern, struct);
View Full Code Here

        if (superclassName == null) {
          superclassName = javaClass.getSuperclassName();
        }
        superclassSignature = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(superclassName)).getSignature();
      }
      World world = getResolvedTypeX().getWorld();
      supertype = world.resolve(UnresolvedType.forSignature(superclassSignature));
      superTypeReference = new WeakReference<ResolvedType>(supertype);
    }
    return supertype;
  }
View Full Code Here

        AnnotationGen annos[] = javaClass.getAnnotations();
        if (annos == null || annos.length == 0) {
          annotationTypes = ResolvedType.NONE;
          annotations = AnnotationAJ.EMPTY_ARRAY;
        } else {
          World w = getResolvedTypeX().getWorld();
          annotationTypes = new ResolvedType[annos.length];
          annotations = new AnnotationAJ[annos.length];
          for (int i = 0; i < annos.length; i++) {
            AnnotationGen annotation = annos[i];
            String typeSignature = annotation.getTypeSignature();
            ResolvedType rType = w.resolve(UnresolvedType.forSignature(typeSignature));
            if (rType == null) {
              throw new RuntimeException("Whilst unpacking annotations on '" + getResolvedTypeX().getName()
                  + "', failed to resolve type '" + typeSignature + "'");
            }
            annotationTypes[i] = rType;
View Full Code Here

    if (typeToCheck.getWorld().forDEBUG_bridgingCode) {
      System.err.println("  Bridging:seriously considering this might be getting overridden '"
          + methodThatMightBeGettingOverridden + "'");
    }

    World w = typeToCheck.getWorld();

    // Look at erasures of parameters (List<String> erased is List)
    boolean sameParams = true;
    for (int p = 0, max = methodThatMightBeGettingOverridden.getParameterTypes().length; p < max; p++) {
View Full Code Here

  private boolean couldMatch(BcelObjectType bcelObjectType, Pointcut pointcut) {
    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

TOP

Related Classes of org.aspectj.weaver.World$AspectPrecedenceCalculator

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.