Package org.aspectj.weaver

Examples of org.aspectj.weaver.Member


  }

  public static BcelShadow makeMonitorExit(BcelWorld world, LazyMethodGen enclosingMethod, InstructionHandle monitorInstruction,
      BcelShadow enclosingShadow) {
    final InstructionList body = enclosingMethod.getBody();
    Member sig = world.makeJoinPointSignatureForMonitorExit(enclosingMethod.getEnclosingClass(), monitorInstruction);
    BcelShadow s = new BcelShadow(world, SynchronizationUnlock, sig, enclosingMethod, enclosingShadow);
    ShadowRange r = new ShadowRange(body);
    r.associateWithShadow(s);
    r.associateWithTargets(Range.genStart(body, monitorInstruction), Range.genEnd(body, monitorInstruction));
    retargetAllBranches(monitorInstruction, r.getStart());
View Full Code Here


   * method checks for the peculiar set of conditions and if they are true, it has a sneak peek at the code before the call to see
   * what is on the stack.
   */
  public UnresolvedType ensureTargetTypeIsCorrect(UnresolvedType tx) {

    Member msig = getSignature();
    if (msig.getArity() == 0 && getKind() == MethodCall && msig.getName().charAt(0) == 'c' && tx.equals(ResolvedType.OBJECT)
        && msig.getReturnType().equals(ResolvedType.OBJECT) && msig.getName().equals("clone")) {

      // Lets go back through the code from the start of the shadow
      InstructionHandle searchPtr = range.getStart().getPrev();
      while (Range.isRangeHandle(searchPtr) || searchPtr.getInstruction().isStoreInstruction()) { // ignore this instruction -
        // it doesnt give us the
View Full Code Here

      return;
    }
    kindedAnnotationVars = new HashMap<ResolvedType, AnnotationAccessVar>();

    ResolvedType[] annotations = null;
    Member shadowSignature = getSignature();
    Member annotationHolder = getSignature();
    ResolvedType relevantType = shadowSignature.getDeclaringType().resolve(world);

    if (relevantType.isRawType() || relevantType.isParameterizedType()) {
      relevantType = relevantType.getGenericType();
    }

    // Determine the annotations that are of interest
    if (getKind() == Shadow.StaticInitialization) {
      annotations = relevantType.resolve(world).getAnnotationTypes();
    } else if (getKind() == Shadow.MethodCall || getKind() == Shadow.ConstructorCall) {
      ResolvedMember foundMember = findMethod2(relevantType.resolve(world).getDeclaredMethods(), getSignature());
      annotations = getAnnotations(foundMember, shadowSignature, relevantType);
      annotationHolder = getRelevantMember(foundMember, shadowSignature, relevantType);
      relevantType = annotationHolder.getDeclaringType().resolve(world);
    } else if (getKind() == Shadow.FieldSet || getKind() == Shadow.FieldGet) {
      annotationHolder = findField(relevantType.getDeclaredFields(), getSignature());

      if (annotationHolder == null) {
        // check the ITD'd dooberries
        List<ConcreteTypeMunger> mungers = relevantType.resolve(world).getInterTypeMungers();
        for (ConcreteTypeMunger typeMunger : mungers) {
          if (typeMunger.getMunger() instanceof NewFieldTypeMunger) {
            ResolvedMember fakerm = typeMunger.getSignature();
            // if (fakerm.hasAnnotations())
            ResolvedMember ajcMethod = AjcMemberMaker.interFieldInitializer(fakerm, typeMunger.getAspectType());
            ResolvedMember rmm = findMethod(typeMunger.getAspectType(), ajcMethod);
            if (fakerm.equals(getSignature())) {
              relevantType = typeMunger.getAspectType();
              annotationHolder = rmm;
            }
          }
        }
      }
      annotations = ((ResolvedMember) annotationHolder).getAnnotationTypes();

    } else if (getKind() == Shadow.MethodExecution || getKind() == Shadow.ConstructorExecution
        || getKind() == Shadow.AdviceExecution) {

      ResolvedMember foundMember = findMethod2(relevantType.getDeclaredMethods(), getSignature());
      annotations = getAnnotations(foundMember, shadowSignature, relevantType);
      annotationHolder = getRelevantMember(foundMember, annotationHolder, relevantType);
      UnresolvedType ut = annotationHolder.getDeclaringType();
      relevantType = ut.resolve(world);

    } else if (getKind() == Shadow.ExceptionHandler) {
      relevantType = getSignature().getParameterTypes()[0].resolve(world);
      annotations = relevantType.getAnnotationTypes();
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 | Modifier.FINAL | 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

        (fi.opcode == Constants.GETSTATIC || fi.opcode == Constants.PUTSTATIC) ? Modifier.STATIC : 0, fi.getName(cpg),
        fi.getSignature(cpg));
  }

  public Member makeJoinPointSignatureFromMethod(LazyMethodGen mg, MemberKind kind) {
    Member ret = mg.getMemberView();
    if (ret == null) {
      int mods = mg.getAccessFlags();
      if (mg.getEnclosingClass().isInterface()) {
        mods |= Modifier.INTERFACE;
      }
View Full Code Here

  }

  public Member makeJoinPointSignatureForArrayConstruction(LazyClassGen cg, InstructionHandle handle) {
    Instruction i = handle.getInstruction();
    ConstantPool cpg = cg.getConstantPool();
    Member retval = null;

    if (i.opcode == Constants.ANEWARRAY) {
      // ANEWARRAY arrayInstruction = (ANEWARRAY)i;
      Type ot = i.getType(cpg);
      UnresolvedType ut = fromBcel(ot);
View Full Code Here

      return;
    }
    String annotationOfInterestSignature = annoAccessor.getType().getSignature();
    // So we have an entity that has an annotation on and within it is the
    // value we want
    Member holder = annoAccessor.getMember();
    AnnotationAJ[] annos = holder.getAnnotations();
    for (int i = 0; i < annos.length; i++) {
      AnnotationGen annotation = ((BcelAnnotation) annos[i]).getBcelAnnotation();
      if (annotation.getTypeSignature().equals(annotationOfInterestSignature)) {
        List<NameValuePair> vals = annotation.getValues();
        boolean doneAndDusted = false;
View Full Code Here

    for (int i = 0, len = declaredParams.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(paramTypes[i], frameIndex));
      frameIndex += paramTypes[i].getSize();
    }
    // do call to pre
    Member preMethod = AjcMemberMaker.preIntroducedConstructor(aspectType, onType, declaredParams);
    body.append(Utility.createInvoke(fact, null, preMethod));

    // create a local, and store return pre stuff into it.
    int arraySlot = mg.allocateLocal(1);
    body.append(InstructionFactory.createStore(Type.OBJECT, arraySlot));

    // put this on the stack
    body.append(InstructionConstants.ALOAD_0);

    // unpack pre args onto stack
    UnresolvedType[] superParamTypes = explicitConstructor.getParameterTypes();

    for (int i = 0, len = superParamTypes.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
      body.append(Utility.createConstant(fact, i));
      body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
      body.append(Utility.createConversion(fact, Type.OBJECT, BcelWorld.makeBcelType(superParamTypes[i])));
    }

    // call super/this

    body.append(Utility.createInvoke(fact, null, explicitConstructor));

    // put this back on the stack

    body.append(InstructionConstants.ALOAD_0);

    // unpack params onto stack
    Member postMethod = AjcMemberMaker.postIntroducedConstructor(aspectType, onType, declaredParams);
    UnresolvedType[] postParamTypes = postMethod.getParameterTypes();

    for (int i = 1, len = postParamTypes.length; i < len; i++) {
      body.append(InstructionFactory.createLoad(Type.OBJECT, arraySlot));
      body.append(Utility.createConstant(fact, superParamTypes.length + i - 1));
      body.append(InstructionFactory.createArrayLoad(Type.OBJECT));
View Full Code Here

  @Override
  public ShadowMunger parameterizeWith(ResolvedType declaringType, Map<String, UnresolvedType> typeVariableMap) {
    Pointcut pc = getPointcut().parameterizeWith(typeVariableMap, declaringType.getWorld());

    BcelAdvice ret = null;
    Member adviceSignature = signature;
    // allows for around advice where the return value is a type variable (see pr115250)
    if (signature instanceof ResolvedMember && signature.getDeclaringType().isGenericType()) {
      adviceSignature = ((ResolvedMember) signature).parameterizedWith(declaringType.getTypeParameters(), declaringType,
          declaringType.isParameterizedType());
    }
View Full Code Here

TOP

Related Classes of org.aspectj.weaver.Member

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.