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

Charles,

Whenever a subclass gets constructed, the base class constructor will also execute. However, you can discriminate based on the type of the object at runtime. Try this:

public pointcut baseConstruction() : execution( MyClass.new() ) && !this(MySubClass);

If you wanted to exclude ALL subclasses you could use this code:

private interface SubclassOfMyClass {}

declare parents: MyClass+ && !MyClass: SubclassOfMyClass;

public pointcut baseConstruction() : execution( MyClass.new() ) && !this(SubclassOfMyClass);

Ron

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

> ------------Original Message------------
> From: "Charles N. Harvey III" <charlieh@xxxxxxxxx>
> To: aspectj-users@xxxxxxxxxxx
> Date: Wed, Jun-9-2004 1:46 PM
> Subject: [aspectj-users] intercept Class but not SubClass
> 
> Hello.
> I have written a simple aspect to run after MyClass.new is executed.
> Thing is, I also have MySubClass which extends MyClass.  And the aspect
> seems to be intercepting that as well.
> 
> public pointcut myCutting() : execution( MyClass.new() ) && !execution( 
> MySubClass.new() );
> 
> 
> That doesn't seem to be doing it.  Is that correct or is there some other
> way to make sure that no sub-classes get intercepted?
> 
> Thanks a lot.
> 
> 
> Charlie
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> http://dev.eclipse.org/mailman/listinfo/aspectj-users
> 
> 


Back to the top