Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-dev] Adding a field to a direct subclass only...

Hi Alex.

I don't think that AspectJ can allow for that because AspectJ respects
Java's rules for subtyping and inheritance.

I cannot think of a single reason for why it would make sense to have
fields on a direct subclass only. Usually this indicates that the
class hierarchy that you are crosscutting is briken in the first
place.

Eric

2008/8/8 Alex Villazon <alex.villazon@xxxxxxxxxxx>:
> Hi,
>  I'm trying to use ITD to add a field only to a direct subclass of a give
> class (and not to direct and indirect as aspectj allows by default), but I
> cannot find the correct expression to do so. The problem is that I have to
> keep a single value for every instance (ideally I would like to add a field
> to java.lang.Object, but this not possible on Sun's JVM), and if apply the
> aspect to "* && !java.lang.Object" the field is added on every class..
>
>  I want to do something like:
>
>  interface MyInterface {}
>  aspect X {
>     int MyInterface.afield;
>     declare parents: * && isDirectSubclassOf(java.lang.Object) &&
> !java.lang.Object implements MyInterface;
>     ..
>  }
>
>  Is there a way to specify that?
>
>  (I cannot use perthis()/pertarget() because it introduces too much
> overhead..).
>
> Many thanks,
>
> Alex
>
> PS: Is there a way to enable ITD to JDK classes? I was able to weave aspects
> that do not use static crosscutting to JDK classes with ajc, but static
> crosscutting does not apply to JDK classes. Probably an option should be
> added to allow this...
> _______________________________________________
> aspectj-dev mailing list
> aspectj-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-dev
>



-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


Back to the top