blob: bf05040e820753cdc24ad56e015fa95a57300a02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
import org.aspectj.testing.*;
import java.util.*;
/**
* PR#479
* Variant of Hunter Kelly's bug report PR#479.
* Hunter tried to bind two arguments using withincode(..)
* and call(..), but received an error. This does it the right
* way and is working as of 1.0alpha1.
*
* @since 2001.08.06
* @author Jeff Palm
* @report 479
*/
public class MatchingArgumentsInCflow {
public static void main(String[] args) {
new MethodParam().someMethod("arg");
}
}
class MethodParam
{
public void someMethod(String arg)
{
List list = new LinkedList();
list.add(new String(arg+":"+arg));
}
}
aspect MethodParamAspect
{
/*
* Match the top of the call and bind argument
*/
pointcut flow(String s):
cflow(execution(void someMethod(String)) && args(s));
/*
* Bind o to the argument to the list
*/
pointcut some(Object o):
call(* List.add(Object)) && args(o);
/*
* Make sure these arguments are different
* and assert the values.
*/
before (String s, Object o): flow(s) && some(o) {
Tester.checkEqual(s, "arg");
Tester.checkEqual(o, "arg:arg");
Tester.checkNotEqual(s, o);
}
}
|