[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] cflowbelow and capturing context

This complete program works for me.  Can you perhaps try code style
instead of annotation style?
The pointcut is as I wrote in my previous email.

---
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.Collections;
import java.util.List;

@Retention(RetentionPolicy.RUNTIME)
@interface RuleSet {}

@Retention(RetentionPolicy.RUNTIME)
@interface Category {}

aspect Watcher {
	pointcut computationOfHealth(): execution(public List<Health>
getHealth(AggregateInfo));
	
	before(): computationOfHealth() {System.out.println("advice on getHealth");}
	
	pointcut category(Category category): execution(@Category * *(..)) &&
cflowbelow(computationOfHealth()) && @annotation(category);

	before(Category category): category(category) {
		System.out.println("advice on @Category tagged method running in
cflow of getHealth");
		System.out.println("category="+category);
	}

	pointcut ruleset(RuleSet rs, Category c): execution(@RuleSet * *(..))
&& cflowbelow(category(c)) && @annotation(rs);
	
	before(RuleSet rs, Category c): ruleset(rs,c) {
		System.out.println("advice on @RuleSet tagged method running in
cflow of something tagged @Category which is in the cflow of
getHealth");
		System.out.println("ruleset="+rs+" category="+c);
	}
	
}

public class AA {
	
	@Category
	public void computationMethod() {
		System.out.println("@Category tagged method running");
		doSomething();
	}
	
	@RuleSet
	public void doSomething() {
		System.out.println("@RuleSet tagged method running");
	}
	
	public List<Health> getHealth(AggregateInfo ai) {
		System.out.println(">getHealth");
		doSomething(); // not advised, not in the cflow of an @Category tagged thing
		computationMethod(); // called in the cflow of getHealth()
		doSomething(); // not advised, not in the cflow of an @Category tagged thing
		System.out.println(">getHealth");
		return Collections.emptyList();		
	}
	
	public static void main(String[] args) {
		AA aa = new AA();
		aa.computationMethod();
		Object o = aa.getHealth(null);
	}
}

class AggregateInfo {}
class Health {}
---

Andy

On 21 May 2010 14:20, Bhaskar Maddala <maddalab@xxxxxxxxx> wrote:
> I thought I did try that, however I did again just to be certain
>
>     [iajc] error at AuditorPointcutCaptures.java::0 incompatible
> number of arguments to pointcut, expected 2 found 0
>
>    It is interesting that I get a similar error
>
>    [iajc] [error   0]: error at audit/AuditorPointcutCaptures.java::0
> incompatible number of arguments to pointcut, expected 1 found 0
>
>   when I try
>   @Pointcut("execution(@RuleSet * *(..)) && @annotation(rs)")
>   public void ruleset(RuleSet rs) {
>   }
>
>   But I cannot track that down either and this
>
>   @Pointcut("execution(@Category * *(..)) &&
> cflowbelow(computationOfHealth()) && @annotation(category)")
>   public void category(Category category) {
>   }
>
>   works fine, so I am flummoxed.
>
> -Bhaskar
>
>
> On Fri, May 21, 2010 at 2:10 PM, Andy Clement <andrew.clement@xxxxxxxxx> wrote:
>> I haven't tried out this code in a real testcase, but perhaps
>> something like this:
>>
>> @Pointcut("execution(@RuleSet * *(..)) && cflowbelow(category(c)) &&
>> @annotation(rs)")
>> public void ruleset(RuleSet rs, Category c) {
>>
>> Andy
>>
>> On 21 May 2010 13:56, Bhaskar Maddala <maddalab@xxxxxxxxx> wrote:
>>> Hello,
>>>
>>>    I am trying to write a few point cuts and capture context and am
>>> having trouble capturing the necessary context
>>>
>>>    Capture the execution pointcut for the Calculation.getHealth JP
>>> method invocation
>>>    @Pointcut("execution(public java.util.List<metrics.Health>
>>> metrics.Calculation.getHealth(metrics.AggregateInfo))")
>>>    public void computationOfHealth() {
>>>    }
>>>
>>>    execution of any methods with the @Category annotation in the
>>> cflowbelow computationOfHealth capture the annotation
>>>    @Pointcut("execution(@Category * *(..)) &&
>>> cflowbelow(computationOfHealth()) && @annotation(category)")
>>>    public void category(Category category) {
>>>    }
>>>
>>>   Require help here-
>>>   execution of any methods with the @RuleSet annotation in the
>>> cflowbelow category
>>>   I would like to capture the ruleset (and if possible) the Category annotation
>>>   @Pointcut("execution(@RuleSet * *(..)) &&
>>> cflowbelow(category(Category)) && @annotation(rs)")
>>>    public void ruleset(RuleSet rs) {
>>>    }
>>>
>>>   I have tried a couple of different options
>>>
>>>   Not what I want but worth a shot
>>>   @Pointcut("execution(@RuleSet * *(..)) && @annotation(rs)")
>>>   and
>>>   @Pointcut("execution(@RuleSet * *(..)) &&
>>> cflowbelow(category(Category)) && @annotation(rs)")
>>>    with the error message
>>>     [iajc] MessageHolder:  (6 weaveinfo)  (530 info)  (1 error)
>>>     [iajc] [error   0]: error at
>>> audit/AuditorPointcutCaptures.java::0 incompatible number of arguments
>>> to pointcut, expected 1 found 0
>>>
>>>     Assistance much appreciated.
>>>
>>> Thanks
>>> Bhaskar
>>> _______________________________________________
>>> 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
>>
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>