[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] LTW and pointcut not matched with @target and inheritance
|
This is an interesting example, it's working as designed but the
design is not intuitive (and it's not my fault ;) ).
By default, annotations are *not* inherited (that's just the Java 5
rules). So when you define
@MemberOfMonitoredSet
public interface AnnotatedService {}
then according to Java, the class
public class AnnotatedServiceImpl implements AnnotatedService {...}
is a misnomer because AnnotatedServiceImpl *does not* have the
@MemberOfMonitoredSet annotation.
When extending a *class*, if the superclass has an annotation that
itself has the @Inherited annotation, then that annotation *will* be
inherited. @Inherited is not honoured for interfaces though.
These are the Java rules, I find them strange, but there you go. I
documented this in the AJDK at
http://www.eclipse.org/aspectj/doc/next/adk15notebook/annotations.html#d0e694
which you might want to look at for futher reference.
Since you used @target() we'll always be matching against the actual
runtime type of the target object (an AnnotatedServiceImpl) and this
doesn't have the annotation, so no match.
A pointcut:
pointcut callOnAnnotatedInterface() :
call (* (@MemberOfMonitoredSet *)+.*(..))
will match a call to any method on a type that has the
@MemberOfMonitoredSet annotation (@MemberOfMonitoredSet *), or any
subtype thereof ("+") - but this form doesn't allow binding of course
if you need to get the annotation value.
Regards, A.
On 11/08/05, Valerio Schiavoni <ervalerio@xxxxxxxxxx> wrote:
> I'm attaching a junit testcase to demostrate the problem.
>
> i didn't include aspectj jar files: just untar the tgz, create an
> externals/ directory inside the ltwtest and launch ant compile test.
>
> the archive contains 4 classes and 1 aspect:
> -Service
> it provides a print(String) method;
> -AnnotatedService
> it extends Service interface, without adding any method: it has a
> marker annotation of type MemberOfMonitoredSet;
> - AnnotatedServiceImpl
> it implements the AnnotatedService interface;
> -MemberOfMonitoredSet
> a custom marker annotation, with rentention policy set to RUNTIME:
> its target is EelementType.TYPE;
>
> -MonitorAspect
> a named pointcut "callOnAnnotatedInterface" is declared, to match
> against calls on any method declared on implementations of the
> AnnotatedService or subtypes AND where the target object is annotated
> with the MemberOfMonitoredSet;
> a single before advice for the callOnAnnotatedInterface pointcut;
>
> The META-INF/aop.xml describes the concrete aspect to be used by the LTW
> mechanism.
> With the settings above, the advice is never used.
>
> But, if the marker annotation is removed from the AnnotatedService
> interface, and the concrete implementation AnnotatedServiceImpl is
> annotated with the MemberOfMonitoredSet, WITHOUT changing in any way the
> MonitorAspect, then the advice is properly invoked.
>
> If this is a known bug, i'll arise a bug in bugzilla. If not....help :-)
>
> cheers,
> Valerio
>
>
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>
>
>
--
-- Adrian
adrian.colyer@xxxxxxxxx