joinPoint.toString(),
new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
Constants.GETFIELD)
);
BranchInstruction ifNotNull = factory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(ifNotNull);
il.append(factory.createLoad(Type.OBJECT, 0));
il.append(factory.createNew(TransformationUtil.THREAD_LOCAL_CLASS));
il.append(InstructionConstants.DUP);
il.append(factory.createInvoke(
TransformationUtil.THREAD_LOCAL_CLASS,
"<init>",
Type.VOID,
Type.NO_ARGS,
Constants.INVOKESPECIAL)
);
il.append(factory.createFieldAccess(
cg.getClassName(),
joinPoint.toString(),
new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
Constants.PUTFIELD)
);
// Object joinPoint = ___jp.get();
BranchInstruction biIfNotNull = null;
InstructionHandle ihIfNotNull = null;
ifNotNull.setTarget(il.append(factory.createLoad(Type.OBJECT, 0)));
il.append(factory.createFieldAccess(
cg.getClassName(),
joinPoint.toString(),
new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
Constants.GETFIELD
));
il.append(factory.createInvoke(
TransformationUtil.THREAD_LOCAL_CLASS,
"get",
Type.OBJECT,
Type.NO_ARGS,
Constants.INVOKEVIRTUAL
));
il.append(factory.createStore(Type.OBJECT, indexJoinPoint));
// if (joinPoint == null) {
il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
biIfNotNull = factory.createBranchInstruction(Constants.IFNONNULL, null);
il.append(biIfNotNull);
// joinPoint = new MemberMethodJoinPoint(uuid, this, "foo.bar.Baz", 10);
il.append(factory.createNew(TransformationUtil.MEMBER_METHOD_JOIN_POINT_CLASS));
il.append(InstructionConstants.DUP);
il.append(new PUSH(cp, uuid));
il.append(factory.createLoad(Type.OBJECT, 0));
il.append(new PUSH(cp, cg.getClassName()));
il.append(new PUSH(cp, methodId));
il.append(new PUSH(cp, controllerClassName));
il.append(factory.createInvoke(
TransformationUtil.MEMBER_METHOD_JOIN_POINT_CLASS,
"<init>",
Type.VOID,
new Type[]{Type.STRING, Type.OBJECT, Type.STRING, Type.INT, Type.STRING},
Constants.INVOKESPECIAL
));
il.append(factory.createStore(Type.OBJECT, indexJoinPoint));
// ___jp.set(joinPoint);
il.append(factory.createLoad(Type.OBJECT, 0));
il.append(factory.createFieldAccess(
cg.getClassName(),
joinPoint.toString(),
new ObjectType(TransformationUtil.THREAD_LOCAL_CLASS),
Constants.GETFIELD
));
il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
il.append(factory.createInvoke(
TransformationUtil.THREAD_LOCAL_CLASS,
"set",
Type.VOID,
new Type[]{Type.OBJECT},
Constants.INVOKEVIRTUAL
));
ihIfNotNull = il.append(factory.createLoad(Type.OBJECT, indexJoinPoint));
il.append(factory.createCheckCast(TransformationUtil.MEMBER_METHOD_JOIN_POINT_TYPE));
indexJoinPoint += 2;
il.append(factory.createStore(Type.OBJECT, indexJoinPoint));
biIfNotNull.setTarget(ihIfNotNull);
// if we have parameters, wrap them up
if (Type.getArgumentTypes(originalMethod.getSignature()).length != 0) {
// create and allocate the parameters array