blob: 64c6ec168e0f637cce9f040d17940f3da734790a (
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
|
import java.lang.reflect.Field;
import org.aspectj.lang.reflect.*;
public aspect Instrumentation {
pointcut nofl() : !within(Instrumentation);
pointcut getField() : get(* *) && nofl() && !get(* System.out) ;
after() : getField() {
final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart.getSignature();
StringBuffer jpInfo = new StringBuffer();
jpInfo.append("getField(* ").append(signature.getName()).append(")");
final Field field = signature.getField();
jpInfo.append(" getField()='").append(signature.getField()).append("'");
final Class<?> declaringType = signature.getDeclaringType();
jpInfo.append(" getDeclaringType()='"+declaringType).append("'");
final Object receiver = thisJoinPoint.getTarget();
if (receiver == null) {
jpInfo.append(" signature.getTarget() is null (only ok if static)");
}
System.out.println(jpInfo.toString());
}
/*
pointcut setField() : set(* *) && nofl();
after() : setField() {
System.out.println("setField()");
final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart
.getSignature();
final Field field = signature.getField();
if (field == null)
System.out.println(" - field " + signature.getName()
+ " is null...bug!");
final Class<?> declaringType = signature.getDeclaringType();
if (declaringType == null)
System.out.println(" - declaringType for the field "
+ signature.getName() + " is null...bug!");
final Object receiver = thisJoinPoint.getTarget();
if (receiver == null)
System.out.println(" - target (receiver) for the field "
+ signature.getName() + " is null...bug!");
}
*/
}
|