[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [aspectj-users] @Entity but not subclass of @Entity
|
Hi Andy,
I think I didn't explain it clearly. I have
@Entity
public class Bean {
}
and a number of sub-beans :
@Entity
public class SubBean extends Bean {
}
How can I match Bean but not SubBean based on the @Entity annotation?
That is, how can I write "A class annotated with @Entity which is NOT a
subclass of another class annotated with @Entity".
Since the only "subclass" operator in AspectJ is the "+", which is
inclusive, writing (@Entity *) && !((@Entity *)+) is useless, as it
would be using an interface instead of (@Entity *).
If I had a construct to say "only subclasses" (suppose #, merely for
illustrative purposes) I could write:
- (@Entity *) && ((@Entity *)#) to find only those entities which super
class is also an entity
- (@Entity *) && !((@Entity *)#) to find only those classes which are
entities but does not extend another entity
- (Bean) && !(Bean#), as a slower alternative to within(Bean).
Such an operator is not present cause it is (nearly) useless when only
classes and interfaces are used, because :
- They are always inherited, as opposed to annotations
- Declaring an interface on a class and on one or more of its subclasses
is (nearly) useless and has no strange side effects.
- Taking ITD methods with that interface would result in method
overriding with same implementation, which is (usually) acceptable and
invisible.
But annotations are more flexible from this point of view, and in this
case I need a bit more flexibility.
Is there a way to emulate this?
The "if" pointcut could solve situations where we are advicing
(if(!thisJoinPointStaticPart.getSignature().getDeclaringType().getSuperClass().hasAnnotation(Entity.class)))
but not when we are declaring parents cause a TypePattern is required
there, nor when we are declaring a warning cause "if" is not statically
determinable.
Am I missing something relevant here?
Simone
Andy Clement wrote:
Just to mention a possibly existing bug in this area to do with
annotation inheritance:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=128664
Andy
2009/8/12 Simone Gianni <simoneg@xxxxxxxxxx <mailto:simoneg@xxxxxxxxxx>>
Hi All,
I have a problem. I add some methods to beans annotated with
@Entity. Some @Entity extends other @Entity, with the result that
methods are added to both types. I added a check to avoid adding
them if they are already there (using !hasmethod(...)), but it
works or does not work depending on the class loading sequence
(which is IMHO a bug I'll write another mail about).
Anyway, it could be easy to solve writing "Apply this to @Entity
beans that does not subclass another @Entity bean", I tried
writing "(@Entity *) && !((@Entity *)+)", but it does not work
obviously. I also tried an if on thisJoinPointStaticPart, but it
is not usable there.
Is there a way to do it? Is there an "exclusive +" that matches
subclasses but not also the base class? While it is handy to write
execution(MyClass+ .....) to match both class and subclass, and
while there is a way to select all subclasses when the class name
is known, I can't find a way to do it with annotations.
Simone
--
Simone Gianni CEO Semeru s.r.l. Apache Committer
http://www.simonegianni.it/
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx <mailto:aspectj-users@xxxxxxxxxxx>
https://dev.eclipse.org/mailman/listinfo/aspectj-users
------------------------------------------------------------------------
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users
--
Simone Gianni CEO Semeru s.r.l. Apache Committer
http://www.simonegianni.it/