Package org.aspectj.apache.bcel.generic

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


   * @param enclosingMethod where to find ih's instruction list.
   */
  public static void replaceInstruction(InstructionHandle ih, InstructionList replacementInstructions,
      LazyMethodGen enclosingMethod) {
    InstructionList il = enclosingMethod.getBody();
    InstructionHandle fresh = il.append(ih, replacementInstructions);
    deleteInstruction(ih, fresh, enclosingMethod);
  }
View Full Code Here


    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(Utility.createGet(factory, AjcMemberMaker.perSingletonField(aspectType)));
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionFactory.PUSH(classGen.getConstantPool(), true));
    il.append(InstructionFactory.createReturn(Type.INT));
    InstructionHandle ifElse = il.append(InstructionFactory.PUSH(classGen.getConstantPool(), false));
    il.append(InstructionFactory.createReturn(Type.INT));
    ifNull.setTarget(ifElse);
  }
View Full Code Here

    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);
    il.append(Utility.createSet(factory, AjcMemberMaker.initFailureCauseField(aspectType)));
    il.append(InstructionFactory.createReturn(Type.VOID));
    tryEnd.setTarget(il.getEnd());

    // replace the original "return" with a "nop"
    // TODO AV - a bit odd, looks like Bcel alters bytecode and has a IMPDEP1 in its representation
    if (clinit.getBody().getEnd().getInstruction().opcode == Constants.IMPDEP1) {
      clinit.getBody().getEnd().getPrev().setInstruction(InstructionConstants.NOP);
    }
    clinit.getBody().getEnd().setInstruction(InstructionConstants.NOP);
    clinit.getBody().append(il);

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

    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

    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));
    InstructionHandle ifEqElse = il.append(InstructionConstants.ICONST_0);
    ifEq.setTarget(ifEqElse);
    ifNull.setTarget(ifEqElse);
    il.append(InstructionFactory.createReturn(Type.INT));
  }
View Full Code Here

    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

        .isInJava5Mode()));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    InstructionHandle tryStart = il.append(InstructionConstants.ALOAD_0);

    il.append(Utility.createInvoke(factory, Constants.INVOKESTATIC, AjcMemberMaker.perTypeWithinGetInstance(aspectType)));
    il.append(InstructionConstants.ASTORE_1);
    il.append(InstructionConstants.ALOAD_1);
    InstructionBranch ifNonNull = InstructionFactory.createBranchInstruction(Constants.IFNONNULL, null);
    il.append(ifNonNull);
    il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    il.append(InstructionConstants.DUP);
    il.append(InstructionFactory.PUSH(classGen.getConstantPool(), aspectType.getName()));
    il.append(InstructionConstants.ACONST_NULL);
    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(InstructionConstants.ALOAD_1);
    ifNonNull.setTarget(ifElse);
    il.append(InstructionFactory.createReturn(Type.OBJECT));

    InstructionHandle handler = il.append(InstructionConstants.ASTORE_1);
    il.append(factory.createNew(AjcMemberMaker.NO_ASPECT_BOUND_EXCEPTION.getName()));
    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);

    method.addExceptionHandler(tryStart, handler.getPrev(), handler, new ObjectType("java.lang.Exception"), false);
  }
View Full Code Here

        .isInJava5Mode()));
    flagAsSynthetic(method, false);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    InstructionHandle tryStart = il.append(InstructionConstants.ALOAD_0);
    il.append(Utility.createInvoke(factory, Constants.INVOKESTATIC, AjcMemberMaker.perTypeWithinGetInstance(aspectType)));
    InstructionBranch ifNull = InstructionFactory.createBranchInstruction(Constants.IFNULL, null);
    il.append(ifNull);
    il.append(InstructionConstants.ICONST_1);
    il.append(InstructionConstants.IRETURN);
    InstructionHandle ifElse = il.append(InstructionConstants.ICONST_0);
    ifNull.setTarget(ifElse);
    il.append(InstructionConstants.IRETURN);

    InstructionHandle handler = il.append(InstructionConstants.ASTORE_1);
    il.append(InstructionConstants.ICONST_0);
    il.append(InstructionConstants.IRETURN);

    method.addExceptionHandler(tryStart, handler.getPrev(), handler, new ObjectType("java.lang.Exception"), false);
  }
View Full Code Here

    LazyMethodGen method = makeMethodGen(classGen, AjcMemberMaker.perTypeWithinGetInstance(aspectType));
    flagAsSynthetic(method, true);
    classGen.addMethodGen(method);

    InstructionList il = method.getBody();
    InstructionHandle tryStart = il.append(InstructionConstants.ALOAD_0);
    il.append(InstructionFactory.PUSH(factory.getConstantPool(), NameMangler.perTypeWithinLocalAspectOf(aspectType)));
    il.append(InstructionConstants.ACONST_NULL);// Class[] for "getDeclaredMethod"
    il.append(factory.createInvoke("java/lang/Class", "getDeclaredMethod", Type.getType("Ljava/lang/reflect/Method;"),
        new Type[] { Type.getType("Ljava/lang/String;"), Type.getType("[Ljava/lang/Class;") }, Constants.INVOKEVIRTUAL));
    il.append(InstructionConstants.ACONST_NULL);// Object for "invoke", static method
    il.append(InstructionConstants.ACONST_NULL);// Object[] for "invoke", no arg
    il.append(factory.createInvoke("java/lang/reflect/Method", "invoke", Type.OBJECT, new Type[] {
        Type.getType("Ljava/lang/Object;"), Type.getType("[Ljava/lang/Object;") }, Constants.INVOKEVIRTUAL));
    il.append(factory.createCheckCast((ReferenceType) BcelWorld.makeBcelType(aspectType)));
    il.append(InstructionConstants.ARETURN);

    InstructionHandle handler = il.append(InstructionConstants.ASTORE_1);
    il.append(InstructionConstants.ACONST_NULL);
    il.append(InstructionConstants.ARETURN);

    method.addExceptionHandler(tryStart, handler.getPrev(), handler, new ObjectType("java.lang.Exception"), false);
  }
View Full Code Here

TOP

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

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.