Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] intercept Class but not SubClass

I think the core of the issue is the distinction between static typing and dynamic typing. It's certainly true that AspectJ makes awareness of this distinction even more important than it is for Java development (although I think it is important there too).

this(Type) matches anything whose runtime (dynamic) type includes Type, whereas declare parents and declared type patterns (e.g., call(* (Type && !Type+).method(..))) match based on the compile time type (static typing).

This is closely related to the same concept in Java (and many other OO languages) where

base.method() is dispatched based on the dynamic type (at runtime) of base (the target), but
someOtherMethod(base) is dispatched based on the static type (at compile time) of base (the argument). E.g., if we have 
Derived derived = new Derived();
Base base = derived;

Then these two calls can result in invoking different methods:
someOtherMethod(base); 
someOtherBase(derived);

I could see it as being valuable to allow type patterns in the this pointcut designator. If this were allowed, then we could just say this(Type+ && !Type). I believe this isn't allowed because of efficiency concerns for the weaver.

By the way, I have proposed a - operator be added to AspectJ, but the way I suggested it would work, this(MyClass-) would match MyClass or any of its base classes (i.e., anything that extended Object).

Ron

Ron Bodkin
Chief Technology Officer
New Aspects of Software
o: (415) 824-4690
m: (415) 509-2895

> ------------Original Message------------
> From: Eric Tanter <etanter@xxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Wed, Jun-9-2004 3:05 PM
> Subject: Re: [aspectj-users] intercept Class but not SubClass
> 
> Thanks Ron.
> 
> Actually, it is understandable as a solution, but maybe not the way 
> users want to think about it.
> 
> The whole "trick" is needed because (as I understand it), in declare 
> parents:
> - MyClass means "MyClass only"
> - MyClass+ means "MyClass + subtypes"
> 
> and in the this PCD:
> - MyClass means "MyClass + subtypes".
> 
> Isn't this a semantic mismatch?
> There is no direct means in the this PCD to refer to "MyClass only".
> 
> Ideally, for avoiding confusion for users, both ways should be similar, 
> independently of whether they are doing an inter-type declaration or 
> specifying a type pattern in a PCD.
> But if the idea is not to change the current semantics of the type 
> pattern within the this PCD (so that a change does not break old code), 
> then a possibility would be to add a way to say "and not its 
> subclasses", something like:
> 
> pointcut baseConstruction() :
>    execution(MyClass.new()) && !this(MyClass-);
> 
> And then you don't need to be adding a marker interface and all.
> 
> ?
> 
> Regards,
> 
> -- Eric
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top