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

Thank you for your response.

!within(anonymous *) was exactly what I was looking for. It's a pity that it's not yet supported.
I looked at link you sent. I think it would be really great if things mentioned there will be supported in one of future releases.

I am writing pertype aspect that I will be able to turn on/off by setting boolean property. It will never do anything with anonymous classes. So thanks for the workaround, but because it uses runtime check, it's easier for me to check just that boolean property. At least that's a plan, I hadn't time to give it try yet :).

One more question. I'm still quiet new in aspectj, so please don't blame me, if it doesn't make a sense.
Would it be possible to have joinpoint for access to critical section? I mean to synchronized block or to synchronized method?

thanks
Peter


On 18. 3. 2010 17:52, Andy Clement wrote:
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


    
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users

  


Back to the top