Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] pointcut for any method of any type except those of anonymous inner classes

What I expect you are looking for is something like

pointcut all(): execution(* *.*(..)) && !within(anonymous *);

But that isn't supported - see discussion in
https://bugs.eclipse.org/bugs/show_bug.cgi?id=44365 comment 2, which
would allow interface/class/aspect/anonymous/inner.

That bug also discusses the options "within(isAnonymous())" and
"within(@AnonymousType *)".

This example below will work for you, but isn't super optimal due to
the runtime check:

---
public aspect Demo {

	public static void main(String[] args) {
		new Foo().foo();
	}
	before(): execution(* *(..)) &&
if(!thisJoinPointStaticPart.getSignature().getDeclaringType().isAnonymousClass()){
		System.out.println("advised "+thisJoinPoint);
	}
}

class Foo {
	Runnable r = new Runnable() {
		public void run() {
		}
	};
	
	class Bar {
		public void bar() {}
	}
	
	public void foo() {
		new Bar().bar();
		r.run();
	}
}
---

I am rev'ing the bytecode format for 1.6.9 so this would be a good
time to put something like the changes discussed in that bug into AJ,
if we can agree on the best syntax.

Andy


2010/3/17 Peter Kvokacka <kvokacka@xxxxxxxxx>:
> Hello guys
>
> I'm struggling with writing pointcut in aspectj for any method of any type
> except those of anonymous inner classes.
>
> Does anybody know what should I add to
>     pointcut all() : execution(* *.*(..))
> if I want to exclude methods of anonymous inner classes?
>
> I can't google it out. I found only this
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=73050#c6
>
> Adrian Colyer 2005-11-04 08:15:01 EST
>
> I've just commited the fix for this and it will be available in the next
> published build. Anonymous types are
> now only matched by the name pattern "*" - any other pattern fails to match
> since anonymous types are
> treated as having no name.
>
> so I tried:
>     pointcut all() : execution(* *.*(..)) && !within(*.*)
>
> which surprisingly works but only for types that are in same package as
> aspect is.
>
> Peter
>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>
>


Back to the top