Hoi Jan,
I think what you did not realise is that call pointcuts match based on
the declared type.
Thus, your advice does not run on the call
new SomeSubClass().someMethod();
but does run when you use
((SomeInterface)new SomeSubClass()).someMethod();
You can modify the pointcut to include the SomeInterface subclasses to
also include the top method call:
pointcut someCall(): call(void SomeInterface+.someMethod());
cheers,
- Gijs Peek
Jan Van Besien wrote:
> Hi all
>
> I recently bumped into a problem using aspectJ that I can't seem
to
> explain. If I implement an interface by subclassing from a class
> that happens to have the correct methods to implement the
interface
> (but doesn't implement the interface in intself), aspectJ advices
> are not being executed with call or execution pointcuts for a
> method in the implemented interface.
>
> An example:
>
> 1) Interface to be implemented: SomeInterface.java
>
> public interface SomeInterface { void someMethod(); }
>
> 2) Class with correct methods, without implementing the
interface:
> SomeClass.java
>
> public class SomeClass { public void someMethod() {
> System.out.println("some method in some class"); } }
>
> 3) Subclass that implements the interface by extending from
> SomeClass: SomeSubClass.java
>
> public class SomeSubClass extends SomeClass implements
> SomeInterface {}
>
> 4) A simple aspect:
>
> aspect SomeAspect { pointcut someCall(): call(void
> SomeInterface.someMethod());
>
> before(): someCall() { System.out.println("Entering: " +
> thisJoinPoint); } }
>
> Now, when you call 'someMethod' on an instance of SomeSubClass,
the
> advice is not executed.
>
> new SomeSubClass().someMethod();
>
> When you let SomeClass implement the SomeInterface interface
> directly, everything works as expected.
>
> What am I missing here?
>
> Thanx in advance Jan
> _______________________________________________ aspectj-users
> mailing list aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
|