Package org.aspectj.apache.bcel.generic

Examples of org.aspectj.apache.bcel.generic.Type


    }

    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;
          }
        }
        if (Modifier.isStatic(rm.getModifiers())) {
          if (rm.getArity() != 0) {
            body.append(InstructionConstants.ALOAD_0);
          }
          body.append(fact.createInvoke(rm.getDeclaringType().getName(), rm.getName(), rm.getSignature(),
              Constants.INVOKESTATIC));
          body.append(Utility.createSet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
        } else {
          // Need to call aspectOf() to obtain the aspect instance then call the factory method upon that
          UnresolvedType theAspect = munger.getAspect();
          body.append(fact.createInvoke(theAspect.getName(), "aspectOf", "()" + theAspect.getSignature(),
              Constants.INVOKESTATIC));
          if (rm.getArity() != 0) {
            body.append(InstructionConstants.ALOAD_0);
          }
          body.append(fact.createInvoke(rm.getDeclaringType().getName(), rm.getName(), rm.getSignature(),
              Constants.INVOKEVIRTUAL));
          body.append(Utility.createSet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
        }
      } else {
        body.append(fact.createNew(munger.getImplClassName()));
        body.append(InstructionConstants.DUP);
        body.append(fact.createInvoke(munger.getImplClassName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
        body.append(Utility.createSet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));
      }

      // if not null use the instance we've got
      InstructionHandle ifNonNullElse = body.append(InstructionConstants.ALOAD_0);
      ifNonNull.setTarget(ifNonNullElse);
      body.append(Utility.createGet(fact, munger.getDelegate(weaver.getLazyClassGen().getType())));

      // args
      int pos = 0;
      if (!Modifier.isStatic(introduced.getModifiers())) { // skip 'this' (?? can this really
        // happen)
        // body.append(InstructionFactory.createThis());
        pos++;
      }
      Type[] paramTypes = BcelWorld.makeBcelTypes(introduced.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, Constants.INVOKEINTERFACE, introduced));
      body.append(InstructionFactory.createReturn(bcelReturnType));

      mg.getBody().append(body);
View Full Code Here


  }

  private static LazyMethodGen makeDispatcher(LazyClassGen onGen, String dispatchName, ResolvedMember superMethod,
      BcelWorld world, boolean isSuper) {
    Type[] paramTypes = BcelWorld.makeBcelTypes(superMethod.getParameterTypes());
    Type returnType = BcelWorld.makeBcelType(superMethod.getReturnType());

    int modifiers = Modifier.PUBLIC;
    if (onGen.isInterface()) {
      modifiers |= Modifier.ABSTRACT;
    }

    LazyMethodGen mg = new LazyMethodGen(modifiers, returnType, dispatchName, paramTypes, UnresolvedType.getNames(superMethod
        .getExceptions()), onGen);
    InstructionList body = mg.getBody();

    if (onGen.isInterface()) {
      return mg;
    }

    // assert (!superMethod.isStatic())
    InstructionFactory fact = onGen.getFactory();
    int pos = 0;

    body.append(InstructionFactory.createThis());
    pos++;
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      pos += paramType.getSize();
    }
    if (isSuper) {
      body.append(Utility.createSuperInvoke(fact, world, superMethod));
    } else {
      body.append(Utility.createInvoke(fact, world, superMethod));
View Full Code Here

      }
      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++) {
View Full Code Here

    InstructionFactory fact;
    LazyMethodGen bridgeMethod = makeMethodGen(gen, bridgingSetter);
    bridgeMethod.setAccessFlags(bridgeMethod.getAccessFlags() | 0x00000040); // BRIDGE = 0x00000040
    Type[] paramTypes = BcelWorld.makeBcelTypes(bridgingSetter.getParameterTypes());
    Type[] bridgingToParms = BcelWorld.makeBcelTypes(itdfieldSetter.getParameterTypes());
    Type returnType = BcelWorld.makeBcelType(bridgingSetter.getReturnType());
    InstructionList body = bridgeMethod.getBody();
    fact = gen.getFactory();
    int pos = 0;

    if (!Modifier.isStatic(bridgingSetter.getModifiers())) {
      body.append(InstructionFactory.createThis());
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      body.append(InstructionFactory.createLoad(paramType, pos));
      if (!bridgingSetter.getParameterTypes()[i].getErasureSignature().equals(
          itdfieldSetter.getParameterTypes()[i].getErasureSignature())) {
        body.append(fact.createCast(paramType, bridgingToParms[i]));
      }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, weaver.getWorld(), itdfieldSetter));
    body.append(InstructionFactory.createReturn(returnType));
    gen.addMethodGen(bridgeMethod);
View Full Code Here

      InstructionList il = method.getBody();
      int register = 0;
      for (int i = 0, max = inlineAccessor.getParameterTypes().length; i < max; i++) {
        UnresolvedType ptype = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(ptype);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Modifier.isStatic(resolvedMember.getModifiers()) ? Constants.INVOKESTATIC
          : Constants.INVOKEVIRTUAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));
View Full Code Here

      InstructionList il = method.getBody();
      il.append(InstructionConstants.ALOAD_0);
      int register = 1;
      for (int i = 0; i < inlineAccessor.getParameterTypes().length; i++) {
        UnresolvedType typeX = inlineAccessor.getParameterTypes()[i];
        Type type = BcelWorld.makeBcelType(typeX);
        il.append(InstructionFactory.createLoad(type, register));
        register += type.getSize();
      }
      il.append(Utility.createInvoke(factory, Constants.INVOKESPECIAL, resolvedMember));
      il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(inlineAccessor.getReturnType())));

      inlineAccessors.put(key, new BcelMethod(aspectGen.getBcelObjectType(), method.getMethod(), methodAttributes));
View Full Code Here

        }
      }
      // A field access instruction may tell us the real type of what the clone() call is on
      if (searchPtr.getInstruction() instanceof FieldInstruction) {
        FieldInstruction si = (FieldInstruction) searchPtr.getInstruction();
        Type t = si.getFieldType(getEnclosingClass().getConstantPool());
        return BcelWorld.fromBcel(t);
      }
      // A new array instruction obviously tells us it is an array type !
      if (searchPtr.getInstruction().opcode == Constants.ANEWARRAY) {
        // ANEWARRAY ana = (ANEWARRAY)searchPoint.getInstruction();
View Full Code Here

  }

  public void weaveCflowEntry(final BcelAdvice munger, final Member cflowField) {
    final boolean isPer = munger.getKind() == AdviceKind.PerCflowBelowEntry || munger.getKind() == AdviceKind.PerCflowEntry;

    final Type objectArrayType = new ArrayType(Type.OBJECT, 1);
    final InstructionFactory fact = getFactory();

    final BcelVar testResult = genTempVar(UnresolvedType.BOOLEAN);

    InstructionList entryInstructions = new InstructionList();
View Full Code Here

    Type[] stateTypes = callbackMethod.getArgumentTypes();
    // System.out.println("stateTypes: " + Arrays.asList(stateTypes));

    for (int i = 0, len = stateTypes.length; i < len; i++) {
      Type stateType = stateTypes[i];
      ResolvedType stateTypeX = BcelWorld.fromBcel(stateType).resolve(world);
      if (proceedMap.hasKey(i)) {
        // throw new RuntimeException("unimplemented");
        proceedVars[proceedMap.get(i)].appendLoadAndConvert(ret, fact, stateTypeX);
      } else {
View Full Code Here

    // store the Object[] array on stack if proceed with args
    if (isProceedWithArgs) {

      // STORE the Object[] into a local variable
      Type objectArrayType = Type.OBJECT_ARRAY;
      int theObjectArrayLocalNumber = localAdviceMethod.allocateLocal(objectArrayType);
      ret.append(InstructionFactory.createStore(objectArrayType, theObjectArrayLocalNumber));

      // STORE the ProceedingJoinPoint instance into a local variable
      Type proceedingJpType = Type.getType("Lorg/aspectj/lang/ProceedingJoinPoint;");
      int pjpLocalNumber = localAdviceMethod.allocateLocal(proceedingJpType);
      ret.append(InstructionFactory.createStore(proceedingJpType, pjpLocalNumber));

      // Aim here initially is to determine whether the user will have provided a new
      // this/target in the object array and consume them if they have, leaving us the rest of
      // the arguments to process as regular arguments to the invocation at the original join point

      boolean pointcutBindsThis = bindsThis(munger);
      boolean pointcutBindsTarget = bindsTarget(munger);
      boolean targetIsSameAsThis = getKind().isTargetSameAsThis();

      int nextArgumentToProvideForCallback = 0;

      if (hasThis()) {
        if (!(pointcutBindsTarget && targetIsSameAsThis)) {
          if (pointcutBindsThis) {
            // they have supplied new this as first entry in object array, consume it
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, 0));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[0]));
          } else {
            // use local variable 0
            ret.append(InstructionFactory.createALOAD(0));
          }
          nextArgumentToProvideForCallback++;
        }
      }

      if (hasTarget()) {
        if (pointcutBindsTarget) {
          if (getKind().isTargetSameAsThis()) {
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, pointcutBindsThis ? 1 : 0));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[0]));
          } else {
            int position = (hasThis()/* && pointcutBindsThis */? 1 : 0);
            ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
            ret.append(Utility.createConstant(fact, position));
            ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
            ret.append(Utility.createConversion(fact, Type.OBJECT, callbackMethod.getArgumentTypes()[position]));
          }
          nextArgumentToProvideForCallback++;
        } else {
          if (getKind().isTargetSameAsThis()) {
            // ret.append(new ALOAD(0));
          } else {
            ret.append(InstructionFactory.createLoad(localAdviceMethod.getArgumentTypes()[0], hasThis() ? 1 : 0));
            nextArgumentToProvideForCallback++;
          }
        }
      }

      // Where to start in the object array in order to pick up arguments
      int indexIntoObjectArrayForArguments = (pointcutBindsThis ? 1 : 0) + (pointcutBindsTarget ? 1 : 0);

      int len = callbackMethod.getArgumentTypes().length;
      for (int i = nextArgumentToProvideForCallback; i < len; i++) {
        Type stateType = callbackMethod.getArgumentTypes()[i];
        BcelWorld.fromBcel(stateType).resolve(world);
        if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
          ret.append(new InstructionLV(Constants.ALOAD, pjpLocalNumber));
        } else {
          ret.append(InstructionFactory.createLoad(objectArrayType, theObjectArrayLocalNumber));
          ret.append(Utility
              .createConstant(fact, i - nextArgumentToProvideForCallback + indexIntoObjectArrayForArguments));
          ret.append(InstructionFactory.createArrayLoad(Type.OBJECT));
          ret.append(Utility.createConversion(fact, Type.OBJECT, stateType));
        }
      }

    } else {
      Type proceedingJpType = Type.getType("Lorg/aspectj/lang/ProceedingJoinPoint;");
      int localJp = localAdviceMethod.allocateLocal(proceedingJpType);
      ret.append(InstructionFactory.createStore(proceedingJpType, localJp));

      int idx = 0;
      for (int i = 0, len = callbackMethod.getArgumentTypes().length; i < len; i++) {
        Type stateType = callbackMethod.getArgumentTypes()[i];
        /* ResolvedType stateTypeX = */
        BcelWorld.fromBcel(stateType).resolve(world);
        if ("Lorg/aspectj/lang/JoinPoint;".equals(stateType.getSignature())) {
          ret.append(InstructionFactory.createALOAD(localJp));// from localAdvice signature
          // } else if ("Lorg/aspectj/lang/ProceedingJoinPoint;".equals(stateType.getSignature())) {
          // //FIXME ALEX?
          // ret.append(new ALOAD(localJp));// from localAdvice signature
          // // ret.append(fact.createCheckCast(
          // // (ReferenceType) BcelWorld.makeBcelType(stateTypeX)
          // // ));
          // // cast ?
          //
          idx++;
        } else {
          ret.append(InstructionFactory.createLoad(stateType, idx));
          idx += stateType.getSize();
        }
      }
    }

    // do the callback invoke
View Full Code Here

TOP

Related Classes of org.aspectj.apache.bcel.generic.Type

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.