blob: 8e24f9e7c4643b578507a291d90ada00716895dc (
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
import java.util.*;
import org.aspectj.lang.annotation.SuppressAjWarnings;
public aspect AfterReturningExamples {
after() returning : execution(* C.*(..)) {
System.out.println(thisJoinPointStaticPart);
}
pointcut executionOfAnyMethodReturningAList() : execution(List *(..));
// matches all three
after() returning(List<?> listOfSomeType) : executionOfAnyMethodReturningAList() {
for (Object element : listOfSomeType) {
System.out.println("raw " + element);
}
}
// matches bar and goo, with unchecked on goo
after() returning(List<Double> listOfDoubles) : execution(* C.*(..)) {
for(Double d : listOfDoubles) {
System.out.println("a1 " + d);
}
}
// matches only bar
after() returning(List<Double> listOfDoubles) : execution(List<Double> C.*(..)) {
for(Double d : listOfDoubles) {
System.out.println("a2 " + d);
}
}
// matches bar and goo, with no warning
@SuppressAjWarnings
after() returning(List<Double> listOfDoubles) : execution(* C.*(..)) {
for(Double d : listOfDoubles) {
System.out.println("a3 " + d);
}
}
public static void main(String[] args) {
List<Double> ld = new ArrayList<Double>();
ld.add(5.0d);
ld.add(10.0d);
List<String> ls = new ArrayList<String>();
ls.add("s1");
ls.add("s2");
C c = new C();
c.foo(ls);
c.bar(ld);
c.goo(ld);
}
}
class C {
public List<String> foo(List<String> listOfStrings) { return listOfStrings; }
public List<Double> bar(List<Double> listOfDoubles) { return listOfDoubles; }
public List<? extends Number> goo(List<? extends Number> listOfSomeNumberType) { return listOfSomeNumberType; }
}
|