aboutsummaryrefslogtreecommitdiffstats
path: root/tests/bugs160/pr172107/Instrumentation.aj
blob: d937dcbb00e87504d30f35f7cd6bffb5abc49e9d (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
import java.lang.reflect.Field;

import org.aspectj.lang.reflect.*;

public aspect Instrumentation {

	/**
	 * Instrument field reads.
	 */
	pointcut getField() : get(* *) && !within(Instrumentation);

	after() : getField() {
		final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart
				.getSignature();
		final Field field = signature.getField();
		final SourceLocation sl = thisJoinPointStaticPart.getSourceLocation();
		if (field == null) {
			throw new IllegalStateException(
					"See pr172107: get FieldSignature#getField()==null in "
							+ sl.getFileName() + " at line " + sl.getLine());
		}
	}

	/**
	 * Instrument field reads.
	 */
	pointcut setField() : set(* *) && !within(Instrumentation);

	after() : setField() {
		final FieldSignature signature = (FieldSignature) thisJoinPointStaticPart
				.getSignature();
		final Field field = signature.getField();
		final SourceLocation sl = thisJoinPointStaticPart.getSourceLocation();
		if (field == null) {
			throw new IllegalStateException(
					"See pr172107: set FieldSignature#getField()==null in "
							+ sl.getFileName() + " at line " + sl.getLine());
		}
	}
}