Package org.aspectj.apache.bcel.generic

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


    // Time to construct the method itself:
    LazyMethodGen advice = new LazyMethodGen(Modifier.PUBLIC, returnType, adviceName, paramTypes.toArray(new Type[paramTypes
        .size()]), EMPTY_STRINGS, cg);

    InstructionList adviceBody = advice.getBody();

    // Generate code to load the parameters
    int pos = 1; // first slot after 'this'
    for (int i = 0; i < paramTypes.size(); i++) {
      adviceBody.append(InstructionFactory.createLoad(paramTypes.get(i), pos));
      pos += paramTypes.get(i).getSize();
    }

    // Generate the delegate call
    adviceBody.append(cg.getFactory().createInvoke(paa.adviceClass, methodName, signature + returnType.getSignature(),
        Constants.INVOKESTATIC));

    // Generate the right return
    if (returnType == Type.VOID) {
      adviceBody.append(InstructionConstants.RETURN);
    } else {
      if (returnType.getSignature().length() < 2) {
        String sig = returnType.getSignature();
        if (sig.equals("F")) {
          adviceBody.append(InstructionConstants.FRETURN);
        } else if (sig.equals("D")) {
          adviceBody.append(InstructionConstants.DRETURN);
        } else if (sig.equals("J")) {
          adviceBody.append(InstructionConstants.LRETURN);
        } else {
          adviceBody.append(InstructionConstants.IRETURN);
        }
      } else {
        adviceBody.append(InstructionConstants.ARETURN);
      }
    }
    // Add the annotation
    advice.addAnnotation(aaj);
    InstructionHandle start = adviceBody.getStart();

    // Setup the local variable targeters so that the binding will work
    String sig = concreteAspect.name.replace('.', '/');
    start.addTargeter(new LocalVariableTag("L" + sig + ";", "this", 0, start.getPosition()));
    if (paramNames.size() > 0) {
View Full Code Here


  public void insertLoad(InstructionList il, InstructionFactory fact) {
    il.insert(createLoad(fact));
  }

  public InstructionList createCopyFrom(InstructionFactory fact, int oldSlot) {
    InstructionList il = new InstructionList();
    il.append(InstructionFactory.createLoad(BcelWorld.makeBcelType(getType()), oldSlot));
    il.append(createStore(fact));
    return il;
  }
View Full Code Here

    Utility.appendConversion(il, fact, storee.getType(), convertToType);
    il.append(InstructionFactory.createArrayStore(BcelWorld.makeBcelType(convertToType)));
  }

  InstructionList createConvertableArrayStore(InstructionFactory fact, int index, BcelVar storee) {
    InstructionList il = new InstructionList();
    appendConvertableArrayStore(il, fact, index, storee);
    return il;
  }
View Full Code Here

    appendConvertableArrayStore(il, fact, index, storee);
    return il;
  }

  InstructionList createConvertableArrayLoad(InstructionFactory fact, int index, ResolvedType convertTo) {
    InstructionList il = new InstructionList();
    appendConvertableArrayLoad(il, fact, index, convertTo);
    return il;
  }
View Full Code Here

    List<LazyMethodGen> mgs = newParentTarget.getMethodGens();

    // Look for ctors to modify
    for (LazyMethodGen aMethod : mgs) {
      if (LazyMethodGen.isConstructor(aMethod)) {
        InstructionList insList = aMethod.getBody();
        InstructionHandle handle = insList.getStart();
        while (handle != null) {
          if (handle.getInstruction().opcode == Constants.INVOKESPECIAL) {
            ConstantPool cpg = newParentTarget.getConstantPool();
            InvokeInstruction invokeSpecial = (InvokeInstruction) handle.getInstruction();
            if (invokeSpecial.getClassName(cpg).equals(currentParent)
View Full Code Here

    return false;
  }

  private void addFieldGetter(LazyClassGen gen, ResolvedMember field, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    if (Modifier.isStatic(field.getModifiers())) {
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), BcelWorld.makeBcelType(field.getType()),
          Constants.GETSTATIC));
    } else {
      il.append(InstructionConstants.ALOAD_0);
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), BcelWorld.makeBcelType(field.getType()),
          Constants.GETFIELD));
    }
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(field.getType())));
    mg.getBody().insert(il);

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }
View Full Code Here

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }

  private void addFieldSetter(LazyClassGen gen, ResolvedMember field, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    Type fieldType = BcelWorld.makeBcelType(field.getType());

    if (Modifier.isStatic(field.getModifiers())) {
      il.append(InstructionFactory.createLoad(fieldType, 0));
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), fieldType, Constants.PUTSTATIC));
    } else {
      il.append(InstructionConstants.ALOAD_0);
      il.append(InstructionFactory.createLoad(fieldType, 1));
      il.append(fact.createFieldAccess(gen.getClassName(), field.getName(), fieldType, Constants.PUTFIELD));
    }
    il.append(InstructionFactory.createReturn(Type.VOID));
    mg.getBody().insert(il);

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }
View Full Code Here

    gen.addMethodGen(mg, getSignature().getSourceLocation());
  }

  private void addMethodDispatch(LazyClassGen gen, ResolvedMember method, ResolvedMember accessMethod) {
    LazyMethodGen mg = makeMethodGen(gen, accessMethod);
    InstructionList il = new InstructionList();
    InstructionFactory fact = gen.getFactory();
    // Type fieldType = BcelWorld.makeBcelType(field.getType());
    Type[] paramTypes = BcelWorld.makeBcelTypes(method.getParameterTypes());

    int pos = 0;

    if (!Modifier.isStatic(method.getModifiers())) {
      il.append(InstructionConstants.ALOAD_0);
      pos++;
    }
    for (int i = 0, len = paramTypes.length; i < len; i++) {
      Type paramType = paramTypes[i];
      il.append(InstructionFactory.createLoad(paramType, pos));
      pos += paramType.getSize();
    }
    il.append(Utility.createInvoke(fact, (BcelWorld) aspectType.getWorld(), method));
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(method.getReturnType())));

    mg.getBody().insert(il);

    gen.addMethodGen(mg);
  }
View Full Code Here

      gen.addField(fg, getSourceLocation());

      Type fieldType = BcelWorld.makeBcelType(aspectType);
      LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC, fieldType, NameMangler.perObjectInterfaceGet(aspectType),
          new Type[0], new String[0], gen);
      InstructionList il = new InstructionList();
      InstructionFactory fact = gen.getFactory();
      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);

      LazyMethodGen mg1 = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, NameMangler.perObjectInterfaceSet(aspectType),

      new Type[] { fieldType, }, new String[0], gen);
      InstructionList il1 = new InstructionList();
      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);

      gen.addInterface(munger.getInterfaceType().resolve(weaver.getWorld()), getSourceLocation());
View Full Code Here

    // e.g.
    // "public com_blah_SecurityAspect ajc$com_blah_SecurityAspect$localAspectOf()"
    Type fieldType = BcelWorld.makeBcelType(aspectType);
    LazyMethodGen mg = new LazyMethodGen(Modifier.PUBLIC | Modifier.STATIC, fieldType,
        NameMangler.perTypeWithinLocalAspectOf(aspectType), new Type[0], new String[0], gen);
    InstructionList il = new InstructionList();
    // PTWIMPL ?? Should check if it is null and throw
    // NoAspectBoundException
    InstructionFactory fact = gen.getFactory();
    il.append(fact.createFieldAccess(gen.getClassName(), fg.getName(), fieldType, Constants.GETSTATIC));
    il.append(InstructionFactory.createReturn(fieldType));
    mg.getBody().insert(il);
    gen.addMethodGen(mg);
    return true;
    // } else {
    // return false;
View Full Code Here

TOP

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

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.