Examples of InstructionFactory


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

   * @param theBridgeMethod
   */
  private void createBridgeMethod(BcelWorld world, NewMethodTypeMunger munger, ResolvedMember unMangledInterMethod,
      LazyClassGen clazz, Type[] paramTypes, ResolvedMember theBridgeMethod) {
    InstructionList body;
    InstructionFactory fact;
    int pos = 0;

    LazyMethodGen bridgeMethod = makeMethodGen(clazz, theBridgeMethod); // The
    // bridge
    // method
View Full Code Here

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

          }
        }
      }

      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);
View Full Code Here

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

  }

  private boolean mungeNewConstructor(BcelClassWeaver weaver, NewConstructorTypeMunger newConstructorTypeMunger) {

    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();
View Full Code Here

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

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

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

      // );

      ResolvedMember itdfieldGetter = AjcMemberMaker.interFieldInterfaceGetter(field, gen.getType()/* onType */, aspectType);
      LazyMethodGen mg = makeMethodGen(gen, itdfieldGetter);
      InstructionList il = new InstructionList();
      InstructionFactory fact = gen.getFactory();
      if (Modifier.isStatic(field.getModifiers())) {
        il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETSTATIC));
      } else {
        il.append(InstructionConstants.ALOAD_0);
        il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETFIELD));
      }
      il.append(InstructionFactory.createReturn(fieldType));
      mg.getBody().insert(il);

      gen.addMethodGen(mg);

      // Check if we need bridge methods for the field getter and setter
      if (munger.getDeclaredSignature() != null) { // is this munger a
        // parameterized
        // form of some
        // original munger?
        ResolvedMember toBridgeTo = munger.getDeclaredSignature().parameterizedWith(null,
            munger.getSignature().getDeclaringType().resolve(getWorld()), false, munger.getTypeVariableAliases());
        boolean needsbridging = false;
        if (!toBridgeTo.getReturnType().getErasureSignature()
            .equals(munger.getSignature().getReturnType().getErasureSignature())) {
          needsbridging = true;
        }
        if (needsbridging) {
          ResolvedMember bridgingGetter = AjcMemberMaker.interFieldInterfaceGetter(toBridgeTo, gen.getType(), aspectType);
          createBridgeMethodForITDF(weaver, gen, itdfieldGetter, bridgingGetter);
        }
      }

      ResolvedMember itdfieldSetter = AjcMemberMaker.interFieldInterfaceSetter(field, gen.getType(), aspectType);
      LazyMethodGen mg1 = makeMethodGen(gen, itdfieldSetter);
      InstructionList il1 = new InstructionList();
      if (Modifier.isStatic(field.getModifiers())) {
        il1.append(InstructionFactory.createLoad(fieldType, 0));
        il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTSTATIC));
      } else {
        il1.append(InstructionConstants.ALOAD_0);
        il1.append(InstructionFactory.createLoad(fieldType, 1));
        il1.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.PUTFIELD));
      }
      il1.append(InstructionFactory.createReturn(Type.VOID));
      mg1.getBody().insert(il1);

      gen.addMethodGen(mg1);
View Full Code Here

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

  // FIXME asc combine with other createBridge.. method in this class, avoid
  // the duplication...
  private void createBridgeMethodForITDF(BcelClassWeaver weaver, LazyClassGen gen, ResolvedMember itdfieldSetter,
      ResolvedMember bridgingSetter) {
    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));
View Full Code Here

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

  public LazyClassGen(String class_name, String super_class_name, String file_name, int access_flags, String[] interfaces,
      World world) {
    myGen = new ClassGen(class_name, super_class_name, file_name, access_flags, interfaces);
    cp = myGen.getConstantPool();
    fact = new InstructionFactory(myGen, cp);
    regenerateGenericSignatureAttribute = true;
    this.world = world;
  }
View Full Code Here

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

  // Non child type, so it comes from a real type in the world.
  public LazyClassGen(BcelObjectType myType) {
    myGen = new ClassGen(myType.getJavaClass());
    cp = myGen.getConstantPool();
    fact = new InstructionFactory(myGen, cp);
    this.myType = myType;
    world = myType.getResolvedTypeX().getWorld();

    /* Does this class support serialization */
    if (implementsSerializable(getType())) {
View Full Code Here

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

    }
  }

  private InstructionList initInstructionList() {
    InstructionList list = new InstructionList();
    InstructionFactory fact = getFactory();

    // make a new factory
    list.append(fact.createNew(factoryType));
    list.append(InstructionFactory.createDup(1));

    list.append(InstructionFactory.PUSH(getConstantPool(), getFileName()));

    // load the current Class object
    // XXX check that this works correctly for inners/anonymous
    list.append(fact.PUSHCLASS(cp, myGen.getClassName()));
    // XXX do we need to worry about the fact the theorectically this could
    // throw
    // a ClassNotFoundException

    list.append(fact.createInvoke(factoryType.getClassName(), "<init>", Type.VOID, new Type[] { Type.STRING, classType },
        Constants.INVOKESPECIAL));

    list.append(InstructionFactory.createStore(factoryType, 0));
    return list;
  }
View Full Code Here

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

   * Create a single bridge method called 'theBridgeMethod' that bridges to 'whatToBridgeTo'
   */
  private static void createBridgeMethod(BcelWorld world, LazyMethodGen whatToBridgeToMethodGen, LazyClassGen clazz,
      ResolvedMember theBridgeMethod) {
    InstructionList body;
    InstructionFactory fact;
    int pos = 0;

    ResolvedMember whatToBridgeTo = whatToBridgeToMethodGen.getMemberView();

    if (whatToBridgeTo == null) {
      whatToBridgeTo = new ResolvedMemberImpl(Member.METHOD, whatToBridgeToMethodGen.getEnclosingClass().getType(),
          whatToBridgeToMethodGen.getAccessFlags(), whatToBridgeToMethodGen.getName(),
          whatToBridgeToMethodGen.getSignature());
    }
    // The bridge method in this type will have the same signature as the one in the supertype
    LazyMethodGen bridgeMethod = makeBridgeMethod(clazz, theBridgeMethod);
    int newflags = bridgeMethod.getAccessFlags() | 0x00000040;// BRIDGE = 0x00000040

    if ((newflags & 0x00000100) != 0) {
      newflags = newflags - 0x100;// NATIVE = 0x00000100 - need to clear it
    }

    bridgeMethod.setAccessFlags(newflags);
    Type returnType = BcelWorld.makeBcelType(theBridgeMethod.getReturnType());
    Type[] paramTypes = BcelWorld.makeBcelTypes(theBridgeMethod.getParameterTypes());
    Type[] newParamTypes = whatToBridgeToMethodGen.getArgumentTypes();
    body = bridgeMethod.getBody();
    fact = clazz.getFactory();

    if (!whatToBridgeToMethodGen.isStatic()) {
      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 (!newParamTypes[i].equals(paramTypes[i])) {
        if (world.forDEBUG_bridgingCode) {
          System.err.println("Bridging: Cast " + newParamTypes[i] + " from " + paramTypes[i]);
        }
        body.append(fact.createCast(paramTypes[i], newParamTypes[i]));
      }
      pos += paramType.getSize();
    }

    body.append(Utility.createInvoke(fact, world, whatToBridgeTo));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.