Hi,
Given the following high-level pointcuts:
* AnyMethod() : execution(* *(..));
* AnyThrowing() : execution(* *(..) throws (!RuntimeException+));
* AnnotatedClass(SomeAnnotation annotation) : within(@SomeAnnotation *) &&
@within(annotation);
* AnnotatedMethod(SomeAnnotation annotation) : execution(@SomeAnnotation *
*(..)) && @annotation(annotation);
I want to around-advise some logic on the following join points:
1. AnnotatedClass(annotation) && AnyMethod() && !AnyThrowing() &&
!AnnotatedMethod(*);
2. AnnotatedClass(annotation) && AnyThrowing() && !AnnotatedMethod(*);
3. AnnotatedMethod(annotation) && !AnyThrowing();
4. AnnotatedMethod(annotation) && AnyThrowing();
The advise needs the information on the "most specific" @SomeAnnotation, and in
case the advised method throws checked exceptions, I need to re-throw them
unchanged.
Now, for all of these advises, I need to apply the exact same logic around
"proceed();", but I currently have to write it four times. I could reduce it to
two if I didn't care about re-throwing checked exceptions unchanged (or would
be OK to use Unsafe#throwException(Throwable)).
The advises pretty much look like the following (comments to call out the
pointcut specifics):
Object around(final SomeAnnotation annotation)
throws Exception // if it's a checked-throwing pointcut
: SomePointCut(annotation) {
try {
return SomeClass.doSomeStuff(new Callable<Object>(){
@Override public final Object call() throws Exception {
proceed();
}
});
} catch(final RuntimeException re) {
throw re;
} catch(final Exception e) {// if it's **not** a checked-throwing
pointcut
throw new AssertionError("Shouldn't have caught checked
exception"); // if it's **not** a checked-throwing pointcut
} // if it's **not** a checked-throwing pointcut
}
So, SomeClass.doSomeStuff expects a callable, and will ".call()" it and let
thrown exceptions go out unchanged. I'm very annoyed having to create the "new
Callable" in every one of the four advises, so I've tried to have a static
method that gets a ProceedingJoinPoint in, to which I'd pass
"(ProceedingJoinPoint)thisJoinPoint", like so:
private static final Object doSomeStuffAroundProceed(final ProceedingJoinPoint
pjp) {
return SomeClass.doSomeStuff(new Callable<Object>(){
@Override public final Object call() throws Exception {
pjp.proceed();
}
});
}
But it turns out that when I do this, "pjp.proceed()" does nothing. Is there
anything i'm doing wrong.
Other than that, is there a way I could write a single advice that'd advise the
four cases at once?
Thanks in advance,
[ Romain Muller | Software Development Engineer | [email protected] ]
_______________________________________________
aspectj-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/aspectj-users