Package org.aspectj.apache.bcel.generic

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


    String superClassName = "org.aspectj.runtime.internal.AroundClosure";
    Type objectArrayType = new ArrayType(Type.OBJECT, 1);

    LazyClassGen closureClass = new LazyClassGen(closureClassName, superClassName, getEnclosingClass().getFileName(),
        Modifier.PUBLIC, new String[] {}, getWorld());
    InstructionFactory fact = new InstructionFactory(closureClass.getConstantPool());

    // constructor
    LazyMethodGen constructor = new LazyMethodGen(Modifier.PUBLIC, Type.VOID, "<init>", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList cbody = constructor.getBody();
    cbody.append(InstructionFactory.createLoad(Type.OBJECT, 0));
    cbody.append(InstructionFactory.createLoad(objectArrayType, 1));
    cbody.append(fact
        .createInvoke(superClassName, "<init>", Type.VOID, new Type[] { objectArrayType }, Constants.INVOKESPECIAL));
    cbody.append(InstructionFactory.createReturn(Type.VOID));

    closureClass.addMethodGen(constructor);

    // method
    LazyMethodGen runMethod = new LazyMethodGen(Modifier.PUBLIC, Type.OBJECT, "run", new Type[] { objectArrayType },
        new String[] {}, closureClass);
    InstructionList mbody = runMethod.getBody();
    BcelVar proceedVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), 1);
    // int proceedVarIndex = 1;
    BcelVar stateVar = new BcelVar(UnresolvedType.OBJECTARRAY.resolve(world), runMethod.allocateLocal(1));
    // int stateVarIndex = runMethod.allocateLocal(1);
    mbody.append(InstructionFactory.createThis());
    mbody.append(fact.createGetField(superClassName, "state", objectArrayType));
    mbody.append(stateVar.createStore(fact));
    // mbody.append(fact.createStore(objectArrayType, stateVarIndex));

    Type[] stateTypes = callbackMethod.getArgumentTypes();
View Full Code Here


    return newMethod;
  }

  private void addPreInitializationReturnCode(LazyMethodGen extractedMethod, Type[] superConstructorTypes) {
    InstructionList body = extractedMethod.getBody();
    final InstructionFactory fact = getFactory();

    BcelVar arrayVar = new BcelVar(world.getCoreType(UnresolvedType.OBJECTARRAY), extractedMethod.allocateLocal(1));

    int len = superConstructorTypes.length;

    body.append(Utility.createConstant(fact, len));

    body.append(fact.createNewArray(Type.OBJECT, (short) 1));
    arrayVar.appendStore(body, fact);

    for (int i = len - 1; i >= 0; i++) {
      // convert thing on top of stack to object
      body.append(Utility.createConversion(fact, superConstructorTypes[i], Type.OBJECT));
View Full Code Here

      classGen.addField(makeFieldGen(classGen, perTypeWithinForField), null);
    }
  }

  private void generatePerSingletonAspectOfMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perSingletonAspectOfMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    InstructionBranch ifNotNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
    il.append(ifNotNull);
    il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    il.append(InstructionConstants.DUP);
    il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
    il.append(Utility.createGet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
    il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, new Type[] {
        Type.STRING, new ObjectType("java.lang.Throwable") }, Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
    InstructionHandle ifElse = il.append(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    il.append(InstructionFactory.createReturn(Type.OBJECT));
    ifNotNull.setTarget(ifElse);
View Full Code Here

    il.append(InstructionFactory.createReturn(Type.OBJECT));
    ifNotNull.setTarget(ifElse);
  }

  private void generatePerSingletonHasAspectMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perSingletonHasAspectMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
View Full Code Here

    il.append(InstructionFactory.createReturn(Type.INT));
    ifNull.setTarget(ifElse);
  }

  private void generatePerSingletonAjcClinitMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.ajcPostClinitMethod(aspectType));
    flagAsSynthetic(method, true);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(factory.createNew(aspectType.getName()));
    il.append(InstructionConstants.DUP);
    il.append(factory.createInvoke(aspectType.getName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
    il.append(Utility.createSet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    il.append(InstructionFactory.createReturn(Type.VOID));

    // patch <clinit> to delegate to ajc$postClinit at the end
    LazyMethodGen clinit = classGen.getStaticInitializer();
    il = new InstructionList();
    InstructionHandle tryStart = il.append(factory.createInvoke(aspectType.getName(), NameMangler.AJC_POST_CLINIT_NAME,
        Type.VOID, Type.NO_ARGS, Constants.INVOKESTATIC));
    InstructionBranch tryEnd = InstructionFactory.createBranchInstruction(Constants.GOTO, null);
    il.append(tryEnd);
    InstructionHandle handler = il.append(InstructionConstants.ASTORE_0);
    il.append(InstructionConstants.ALOAD_0);
View Full Code Here

    clinit.addExceptionHandler(tryStart, handler.getPrev(), handler, new ObjectType("java.lang.Throwable"), false);
  }

  private void generatePerObjectAspectOfMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    ReferenceType interfaceType = (ReferenceType) BcelWorld.makeBcelType(AjcMemberMaker.perObjectInterfaceType(aspectType));
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perObjectAspectOfMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    il.append(InstructionConstants.DUP);
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionFactory.createReturn(BcelWorld.makeBcelType(aspectType)));
    InstructionHandle ifNullElse = il.append(InstructionConstants.POP);
    ifNull.setTarget(ifNullElse);
    InstructionHandle ifEqElse = il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    ifEq.setTarget(ifEqElse);
    il.append(InstructionConstants.DUP);
    il.append(factory.createInvoke(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName(), "<init>", Type.VOID, Type.NO_ARGS,
        Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
  }
View Full Code Here

        Constants.INVOKESPECIAL));
    il.append(InstructionConstants.ATHROW);
  }

  private void generatePerObjectHasAspectMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    ReferenceType interfaceType = (ReferenceType) BcelWorld.makeBcelType(AjcMemberMaker.perObjectInterfaceType(aspectType));
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perObjectHasAspectMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionConstants.ICONST_1);
    il.append(InstructionFactory.createReturn(Type.INT));
View Full Code Here

    ifNull.setTarget(ifEqElse);
    il.append(InstructionFactory.createReturn(Type.INT));
  }

  private void generatePerObjectBindMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    ReferenceType interfaceType = (ReferenceType) BcelWorld.makeBcelType(AjcMemberMaker.perObjectInterfaceType(aspectType));
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perObjectBind(aspectType));
    flagAsSynthetic(method, true);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createInstanceOf(interfaceType));
    InstructionBranch ifEq = InstructionFactory.createBranchInstruction(Constants.IFEQ, null);
    il.append(ifEq);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceGet(aspectType)));
    InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
    il.append(ifNonNull);
    il.append(InstructionConstants.ALOAD_0);
    il.append(factory.createCheckCast(interfaceType));
    il.append(factory.createNew(aspectType.getName()));
    il.append(InstructionConstants.DUP);
    il.append(factory.createInvoke(aspectType.getName(), "<init>", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
    il.append(Utility.createInvoke(factory, Constants.INVOKEINTERFACE, AjcMemberMaker.perObjectInterfaceSet(aspectType)));
    InstructionHandle end = il.append(InstructionFactory.createReturn(Type.VOID));
    ifEq.setTarget(end);
    ifNonNull.setTarget(end);
  }
View Full Code Here

  // ilSet.append(Utility.createSet(factory, AjcMemberMaker.perObjectField(aspectType, aspectType)));
  // ilSet.append(InstructionFactory.createReturn(Type.VOID));
  // }

  private void generatePerCflowAspectOfMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perCflowAspectOfMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    il.append(Utility.createGet(factory, AjcMemberMaker.perCflowField(aspectType)));
    il.append(Utility.createInvoke(factory, Constants.INVOKEVIRTUAL, AjcMemberMaker.cflowStackPeekInstance()));
    il.append(factory.createCheckCast((ReferenceType) BcelWorld.makeBcelType(aspectType)));
    il.append(InstructionFactory.createReturn(Type.OBJECT));
  }
View Full Code Here

    il.append(factory.createCheckCast((ReferenceType) BcelWorld.makeBcelType(aspectType)));
    il.append(InstructionFactory.createReturn(Type.OBJECT));
  }

  private void generatePerCflowHasAspectMethod(LazyClassGen classGen) {
    InstructionFactory factory = classGen.getFactory();
    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perCflowHasAspectMethod(aspectType));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
View Full Code Here

TOP

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

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.