[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[aspectj-users] withincode and overriden methods

Hi All,

Please see the following code, say, I would like to capture join points inside the Foo.bar() method ONLY, not in any of the overridden versions.

However, only pointcut 3 works. Pointcut 1 and 2 matches bar methods defined in both Foo and SubFoo.

Compared to this, within pointcut works more like what I expected, as in pointcut 4, within(Foo) only matches join points in class Foo, not in any of its subclasses, e.g. SubFoo.

Since withincode and within are used to match join points based on the lexical structure of the program, it seems more reasonable not to implicitly include the subclasses. To match subclasses, we can just use withincode(void Foo+.bar()).

Any comments will be appreciated.

public class Withincode {
	public static void main(String[] args) {
		Foo f = new SubFoo();
	static void log(Object...objects) {
		for(Object o:objects)
	static class Foo {
		public void bar() {
	static class SubFoo extends Foo {
		public void bar() {
	static aspect SomeAspect {
		// 1
		before():withincode(void Foo.bar()){}
		// 2
		before():withincode(void (Foo && !SubFoo).bar()){}
		// 3
		before():!withincode(void SubFoo.bar())
			&&withincode(void Foo.bar()){}
		// 4
		before():within(Foo) {	}