Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] Why does every Aspect (pertarget(..)) add fields and interfaces to classes which are not targeted??

On 08/02/06, Jody Brownell <jody.brownell@xxxxxxxxxx> wrote:
> Hello.
>
> I am writing a series of small POC Aspects which revolve around various
> annotations. I just noticed while debugging that classes not annotated with
> the designated annotations have some extraneous fields/interfaces injected
> during the weaving process.
>
> I was hoping someone could explain what it is, why they are there and how I
> can trim the resulting class files during weaving to be as nimble as
> possible – i.e. remove all the extra fields / interfaces from classes which
> *SHOULD* not be effected by aspects in the first place. Don't get me wrong –
> I understand the need for injecting fields, methods and such to support the
> runtime – but why on classes which have explicitly not been targeted with an
> aspect. Looking at the name (interface FairLockAspect$ajcMightHaveAspect )
> implies this is a forward compatibility feature. Is there a quick way to
> turn this off? I tried the "not reweavable" option in eclipse preferences –
> but that did not help J (I am grabbing at straws)

The interface is there because instances of the object in question may
have an aspect instance associated with them according to the
pointcuts and pertarget clause used by your aspects.  Under bug number
75442 we did some work to reduce the set of types that are marked
through some extra analysis of the pointcuts/perclause - that was
shipped in AspectJ1.5.0M3.  However, there are certain patterns of
usage (some combination of call and pertarget I think) that make it
very tough to work out what may or may not have an aspect instance at
runtime.

You can't turn this off - the best you can do is alter your
pointcut/perclause definition to limit the effects of it - reducing
the set of types that might have an aspect instance at runtime.  The
interface is attached so that code in the aspect that needs to
determine the aspect instance can rely on certain methods being
implemented by types and so easily manipulate them.

> Thanks for the Help!!!! Sorry if I am on crack and have missed something
> real obvious J

Can you supply concrete examples of the pointcuts and perclause for a
typical case where you observe this happening?

Andy.

Back to the top