Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] One target for intertype declarations

Hi Eric,

ITDs cannot hold aspect instances since normally such instances
cannot be created by hand. Google for "association aspects" for a
different approach.

Ok, but that's a minor difference since all I want is to associate state with an object. So, it doesn't have to be an aspect instance --- a simple data structure holding my state will suffice.

Is the reference put into all objects
matching the pertarget pointcut, or just into objects for which an
aspect is created?

Isn't that the same? One aspect instance is created for any object
matching the pertarget pointcut.

Well, I was thinking of something along the following lines:

aspect myAspect pertarget(initialization(*.new()) {
 static int counter = 0;

 before() : initialization(*.new(..)) && !within(myAspect)
	    && if(++counter > 100) {
   ...
   counter = 0;
 }
}

The point about this is that the advice is only entered every 100th time. Meaning that an aspect is only created every 100th time. So, the question is, is there an empty (aspect) reference field for objects which match the pertarget specifier, but never make it into the advice?

The reason I want to do this is simply to associate state with "some" objects, rather than all (i.e. Sampling). Furthermore, i would rather not have any memory overhead associated with those which have no state associated with them.

One a slightly different note, one thing does occur to me in the pertarget versus ITD discussion. Consider the following alternative:

aspect myAspect {
    private interface State {};
    declare parents: * && !java.lang.Object implements State;
    MyState State.ref = null; // will point to my associated state

    ...
}

I think that State.ref will be introduced into every class, meaning objects composed using inheritance will have multiple copies of it? In this case, there is a difference from pertarget, where I presume there can only ever be one reference per object. Comments?

Cheers,

Dave

Eric

- -- Eric Bodden
Chair I2 for Programming Languages and Program Analysis
RWTH Aachen University

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3

iQA/AwUBQZ00gswiFCm7RlWCEQJMKACdEavVNVdD7d8Kc/11JBvoPsuUwZcAoJLp
+rpYtSIUvVVff+cVL7WwJjMo
=ZgIA
-----END PGP SIGNATURE-----


_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
http://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top