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...


On Aug 8, 2008, at 5:05 PM, Eric Bodden wrote:

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.


 Hi Eric,
The use of IDT helps me to enable a counter associated to each object (to avoid using perthis/pertarget because of performance issues and because I cannot add that field on java.lang.Object in Sun VM.. J9 accepts such a modification).

I want to add the field only on direct subclasses of java.lang.Object to avoid the problem of having instance field in subclasses that 'hiddes' the value defined in the super class... This can be problematic if a variable refers to different subclasses, and therefore update the wrong counter... , i.e. my counter is not dependent of the type, but simply per object...

I had such a problem if the field is added in all direct and indirect subclasses..

Cheers,

Alex


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
_______________________________________________
aspectj-dev mailing list
aspectj-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-dev



Back to the top