Package org.aspectj.weaver

Examples of org.aspectj.weaver.Member$Kind


    return new ReflectionShadow(inWorld, kind, signature, null, enclosingType, null, withContext);
  }

  public static Shadow makeInitializationShadow(World inWorld, Constructor forConstructor, MatchingContext withContext) {
    Kind kind = Shadow.Initialization;
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(forConstructor, inWorld);
    ResolvedType enclosingType = signature.getDeclaringType().resolve(inWorld);
    return new ReflectionShadow(inWorld, kind, signature, null, enclosingType, null, withContext);
  }
View Full Code Here


  }

  public static Shadow makeHandlerShadow(World inWorld, Class exceptionType, Class withinType, MatchingContext withContext) {
    Kind kind = Shadow.ExceptionHandler;
    Shadow enclosingShadow = makeStaticInitializationShadow(inWorld, withinType, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createHandlerMember(exceptionType, withinType, inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createStaticInitMember(withinType, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

  public static Shadow makeHandlerShadow(World inWorld, Class exceptionType, java.lang.reflect.Member withinCode,
      MatchingContext withContext) {
    Kind kind = Shadow.ExceptionHandler;
    Shadow enclosingShadow = makeExecutionShadow(inWorld, withinCode, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createHandlerMember(exceptionType,
        withinCode.getDeclaringClass(), inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(withinCode, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }

  public static Shadow makeFieldGetShadow(World inWorld, Field forField, Class callerType, MatchingContext withContext) {
    Shadow enclosingShadow = makeStaticInitializationShadow(inWorld, callerType, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedField(forField, inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createStaticInitMember(callerType, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    Kind kind = Shadow.FieldGet;
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

  }

  public static Shadow makeFieldGetShadow(World inWorld, Field forField, java.lang.reflect.Member inMember,
      MatchingContext withContext) {
    Shadow enclosingShadow = makeExecutionShadow(inWorld, inMember, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedField(forField, inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(inMember, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    Kind kind = Shadow.FieldGet;
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }

  public static Shadow makeFieldSetShadow(World inWorld, Field forField, Class callerType, MatchingContext withContext) {
    Shadow enclosingShadow = makeStaticInitializationShadow(inWorld, callerType, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedField(forField, inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createStaticInitMember(callerType, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    Kind kind = Shadow.FieldSet;
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

  }

  public static Shadow makeFieldSetShadow(World inWorld, Field forField, java.lang.reflect.Member inMember,
      MatchingContext withContext) {
    Shadow enclosingShadow = makeExecutionShadow(inWorld, inMember, withContext);
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedField(forField, inWorld);
    ResolvedMember enclosingMember = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(inMember, inWorld);
    ResolvedType enclosingType = enclosingMember.getDeclaringType().resolve(inWorld);
    Kind kind = Shadow.FieldSet;
    return new ReflectionShadow(inWorld, kind, signature, enclosingShadow, enclosingType, enclosingMember, withContext);
  }
View Full Code Here

   * If the body of the advice can be determined to not alter the stack, or if this shadow doesn't care about the stack, i.e.
   * method-execution, then the new method for the advice can also be re-lined. We are not doing that presently.
   */
  public void weaveAroundInline(BcelAdvice munger, boolean hasDynamicTest) {
    // !!! THIS BLOCK OF CODE SHOULD BE IN A METHOD CALLED weaveAround(...);
    Member mungerSig = munger.getSignature();
    // Member originalSig = mungerSig; // If mungerSig is on a parameterized type, originalSig is the member on the generic type
    if (mungerSig instanceof ResolvedMember) {
      ResolvedMember rm = (ResolvedMember) mungerSig;
      if (rm.hasBackingGenericMember()) {
        mungerSig = rm.getBackingGenericMember();
      }
    }
    ResolvedType declaringAspectType = world.resolve(mungerSig.getDeclaringType(), true);
    if (declaringAspectType.isMissing()) {
      world.getLint().cantFindType.signal(
          new String[] { WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_DURING_AROUND_WEAVE,
              declaringAspectType.getClassName()) }, getSourceLocation(),
          new ISourceLocation[] { munger.getSourceLocation() });
    }

    // ??? might want some checks here to give better errors
    ResolvedType rt = (declaringAspectType.isParameterizedType() ? declaringAspectType.getGenericType() : declaringAspectType);
    BcelObjectType ot = BcelWorld.getBcelObjectType(rt);
    LazyMethodGen adviceMethod = ot.getLazyClassGen().getLazyMethodGen(mungerSig);
    if (!adviceMethod.getCanInline()) {
      weaveAroundClosure(munger, hasDynamicTest);
      return;
    }

    // specific test for @AJ proceedInInners
    if (isAnnotationStylePassingProceedingJoinPointOutOfAdvice(munger, hasDynamicTest, adviceMethod)) {
      return;
    }

    // We can't inline around methods if they have around advice on them, this
    // is because the weaving will extract the body and hence the proceed call.

    // TODO should consider optimizations to recognize simple cases that don't require body extraction

    enclosingMethod.setCanInline(false);

    LazyClassGen shadowClass = getEnclosingClass();

    // Extract the shadow into a new method. For example:
    // "private static final void method_aroundBody0(M, M, String, org.aspectj.lang.JoinPoint)"
    // Parameters are: this if there is one, target if there is one and its different to this, then original arguments
    // at the shadow, then tjp
    String extractedShadowMethodName = NameMangler.aroundShadowMethodName(getSignature(), shadowClass.getNewGeneratedNameTag());
    List<String> parameterNames = new ArrayList<String>();
    LazyMethodGen extractedShadowMethod = extractShadowInstructionsIntoNewMethod(extractedShadowMethodName, Modifier.PRIVATE,
        munger.getSourceLocation(), parameterNames);

    List<BcelVar> argsToCallLocalAdviceMethodWith = new ArrayList<BcelVar>();
    List<BcelVar> proceedVarList = new ArrayList<BcelVar>();
    int extraParamOffset = 0;

    // Create the extra parameters that are needed for passing to proceed
    // This code is very similar to that found in makeCallToCallback and should
    // be rationalized in the future

    if (thisVar != null) {
      argsToCallLocalAdviceMethodWith.add(thisVar);
      proceedVarList.add(new BcelVar(thisVar.getType(), extraParamOffset));
      extraParamOffset += thisVar.getType().getSize();
    }

    if (targetVar != null && targetVar != thisVar) {
      argsToCallLocalAdviceMethodWith.add(targetVar);
      proceedVarList.add(new BcelVar(targetVar.getType(), extraParamOffset));
      extraParamOffset += targetVar.getType().getSize();
    }
    int idx = 0;
    for (int i = 0, len = getArgCount(); i < len; i++) {
      argsToCallLocalAdviceMethodWith.add(argVars[i]);
      proceedVarList.add(new BcelVar(argVars[i].getType(), extraParamOffset));
      extraParamOffset += argVars[i].getType().getSize();
    }
    if (thisJoinPointVar != null) {
      argsToCallLocalAdviceMethodWith.add(thisJoinPointVar);
      proceedVarList.add(new BcelVar(thisJoinPointVar.getType(), extraParamOffset));
      extraParamOffset += thisJoinPointVar.getType().getSize();
    }

    // We use the munger signature here because it allows for any parameterization of the mungers pointcut that
    // may have occurred ie. if the pointcut is p(T t) in the super aspect and that has become p(Foo t) in the sub aspect
    // then here the munger signature will have 'Foo' as an argument in it whilst the adviceMethod argument type will be
    // 'Object' - since it represents the advice method in the superaspect which uses the erasure of the type variable p(Object
    // t) - see pr174449.

    Type[] adviceParameterTypes = BcelWorld.makeBcelTypes(munger.getSignature().getParameterTypes());

    // forces initialization ... dont like this but seems to be required for some tests to pass, I think that means there
    // is a LazyMethodGen method that is not correctly setup to call initialize() when it is invoked - but I dont have
    // time right now to discover which
    adviceMethod.getArgumentTypes();

    Type[] extractedMethodParameterTypes = extractedShadowMethod.getArgumentTypes();

    Type[] parameterTypes = new Type[extractedMethodParameterTypes.length + adviceParameterTypes.length + 1];
    int parameterIndex = 0;
    System.arraycopy(extractedMethodParameterTypes, 0, parameterTypes, parameterIndex, extractedMethodParameterTypes.length);
    parameterIndex += extractedMethodParameterTypes.length;
    parameterTypes[parameterIndex++] = BcelWorld.makeBcelType(adviceMethod.getEnclosingClass().getType());
    System.arraycopy(adviceParameterTypes, 0, parameterTypes, parameterIndex, adviceParameterTypes.length);

    // Extract the advice into a new method. This will go in the same type as the shadow
    // name will be something like foo_aroundBody1$advice
    String localAdviceMethodName = NameMangler.aroundAdviceMethodName(getSignature(), shadowClass.getNewGeneratedNameTag());
    LazyMethodGen localAdviceMethod = new LazyMethodGen(Modifier.PRIVATE | (world.useFinal() ? Modifier.FINAL : 0)
        | Modifier.STATIC, BcelWorld.makeBcelType(mungerSig.getReturnType()), localAdviceMethodName, parameterTypes,
        NoDeclaredExceptions, shadowClass);

    // Doesnt work properly, so leave it out:
    // String aspectFilename = adviceMethod.getEnclosingClass().getInternalFileName();
    // String shadowFilename = shadowClass.getInternalFileName();
    // if (!aspectFilename.equals(shadowFilename)) {
    // localAdviceMethod.fromFilename = aspectFilename;
    // shadowClass.addInlinedSourceFileInfo(aspectFilename, adviceMethod.highestLineNumber);
    // }

    shadowClass.addMethodGen(localAdviceMethod);

    // create a map that will move all slots in advice method forward by extraParamOffset
    // in order to make room for the new proceed-required arguments that are added at
    // the beginning of the parameter list
    int nVars = adviceMethod.getMaxLocals() + extraParamOffset;
    IntMap varMap = IntMap.idMap(nVars);
    for (int i = extraParamOffset; i < nVars; i++) {
      varMap.put(i - extraParamOffset, i);
    }

    final InstructionFactory fact = getFactory();

    localAdviceMethod.getBody().insert(
        BcelClassWeaver.genInlineInstructions(adviceMethod, localAdviceMethod, varMap, fact, true));

    localAdviceMethod.setMaxLocals(nVars);

    // the shadow is now empty. First, create a correct call
    // to the around advice. This includes both the call (which may involve
    // value conversion of the advice arguments) and the return
    // (which may involve value conversion of the return value). Right now
    // we push a null for the unused closure. It's sad, but there it is.

    InstructionList advice = new InstructionList();
    // InstructionHandle adviceMethodInvocation;
    {
      for (Iterator<BcelVar> i = argsToCallLocalAdviceMethodWith.iterator(); i.hasNext();) {
        BcelVar var = i.next();
        var.appendLoad(advice, fact);
      }
      // ??? we don't actually need to push NULL for the closure if we take care
      boolean isAnnoStyleConcreteAspect = munger.getConcreteAspect().isAnnotationStyleAspect();
      boolean isAnnoStyleDeclaringAspect = munger.getDeclaringAspect() != null ? munger.getDeclaringAspect().resolve(world)
          .isAnnotationStyleAspect() : false;

      InstructionList iList = null;
      if (isAnnoStyleConcreteAspect && isAnnoStyleDeclaringAspect) {
        iList = this.loadThisJoinPoint();
        iList.append(Utility.createConversion(getFactory(), LazyClassGen.tjpType, LazyClassGen.proceedingTjpType));
      } else {
        iList = new InstructionList(InstructionConstants.ACONST_NULL);
      }
      advice.append(munger.getAdviceArgSetup(this, null, iList));
      // adviceMethodInvocation =
      advice.append(Utility.createInvoke(fact, localAdviceMethod)); // (fact, getWorld(), munger.getSignature()));
      advice.append(Utility.createConversion(getFactory(), BcelWorld.makeBcelType(mungerSig.getReturnType()),
          extractedShadowMethod.getReturnType(), world.isInJava5Mode()));
      if (!isFallsThrough()) {
        advice.append(InstructionFactory.createReturn(extractedShadowMethod.getReturnType()));
      }
    }
View Full Code Here

    BcelVar[] adviceVars = munger.getExposedStateAsBcelVars(true);

    String closureClassName = NameMangler.makeClosureClassName(getEnclosingClass().getType(), getEnclosingClass()
        .getNewGeneratedNameTag());

    Member constructorSig = new MemberImpl(Member.CONSTRUCTOR, UnresolvedType.forName(closureClassName), 0, "<init>",
        "([Ljava/lang/Object;)V");

    BcelVar closureHolder = null;

    // This is not being used currently since getKind() == preinitializaiton
    // cannot happen in around advice
    if (getKind() == PreInitialization) {
      closureHolder = genTempVar(AjcMemberMaker.AROUND_CLOSURE_TYPE);
    }

    InstructionList closureInstantiation = makeClosureInstantiation(constructorSig, closureHolder);

    /* LazyMethodGen constructor = */
    makeClosureClassAndReturnConstructor(closureClassName, callbackMethod, makeProceedArgumentMap(adviceVars));

    InstructionList returnConversionCode;
    if (getKind() == PreInitialization) {
      returnConversionCode = new InstructionList();

      BcelVar stateTempVar = genTempVar(UnresolvedType.OBJECTARRAY);
      closureHolder.appendLoad(returnConversionCode, fact);

      returnConversionCode.append(Utility.createInvoke(fact, world, AjcMemberMaker.aroundClosurePreInitializationGetter()));
      stateTempVar.appendStore(returnConversionCode, fact);

      Type[] stateTypes = getSuperConstructorParameterTypes();

      returnConversionCode.append(InstructionConstants.ALOAD_0); // put "this" back on the stack
      for (int i = 0, len = stateTypes.length; i < len; i++) {
        UnresolvedType bcelTX = BcelWorld.fromBcel(stateTypes[i]);
        ResolvedType stateRTX = world.resolve(bcelTX, true);
        if (stateRTX.isMissing()) {
          world.getLint().cantFindType.signal(
              new String[] { WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_DURING_AROUND_WEAVE_PREINIT,
                  bcelTX.getClassName()) }, getSourceLocation(),
              new ISourceLocation[] { munger.getSourceLocation() });
          // IMessage msg = new Message(
          // WeaverMessages.format(WeaverMessages.CANT_FIND_TYPE_DURING_AROUND_WEAVE_PREINIT,bcelTX.getClassName()),
          // "",IMessage.ERROR,getSourceLocation(),null,
          // new ISourceLocation[]{ munger.getSourceLocation()});
          // world.getMessageHandler().handleMessage(msg);
        }
        stateTempVar.appendConvertableArrayLoad(returnConversionCode, fact, i, stateRTX);
      }
    } else {
      // pr226201
      Member mungerSignature = munger.getSignature();
      if (munger.getSignature() instanceof ResolvedMember) {
        if (((ResolvedMember) mungerSignature).hasBackingGenericMember()) {
          mungerSignature = ((ResolvedMember) mungerSignature).getBackingGenericMember();
        }
      }
      UnresolvedType returnType = mungerSignature.getReturnType();
      returnConversionCode = Utility.createConversion(getFactory(), BcelWorld.makeBcelType(returnType),
          callbackMethod.getReturnType(), world.isInJava5Mode());
      if (!isFallsThrough()) {
        returnConversionCode.append(InstructionFactory.createReturn(callbackMethod.getReturnType()));
      }
View Full Code Here

  private Map annotationVar = new HashMap();
  private AnnotationFinder annotationFinder;

  public static Shadow makeExecutionShadow(World inWorld, java.lang.reflect.Member forMethod, MatchingContext withContext) {
    Kind kind = (forMethod instanceof Method) ? Shadow.MethodExecution : Shadow.ConstructorExecution;
    Member signature = ReflectionBasedReferenceTypeDelegateFactory.createResolvedMember(forMethod, inWorld);
    ResolvedType enclosingType = signature.getDeclaringType().resolve(inWorld);
    return new StandardShadow(inWorld, kind, signature, null, enclosingType, null, withContext);
  }
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.Member$Kind

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.