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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
/* *******************************************************************
* Copyright (c) 2005 Contributors.
* All rights reserved.
* This program and the accompanying materials are made available
* under the terms of the Eclipse Public License v1.0
* which accompanies this distribution and is available at
* http://eclipse.org/legal/epl-v10.html
*
* Contributors:
* Adrian Colyer Initial implementation
* ******************************************************************/
package org.aspectj.weaver.reflect;
import java.lang.reflect.Member;
import org.aspectj.weaver.ResolvedType;
import org.aspectj.weaver.ast.Var;
/**
* A variable at a reflection shadow, used by the residual tests.
*/
public final class ReflectionVar extends Var {
static final int THIS_VAR = 0;
static final int TARGET_VAR = 1;
static final int ARGS_VAR = 2;
static final int AT_THIS_VAR = 3;
static final int AT_TARGET_VAR = 4;
static final int AT_ARGS_VAR = 5;
static final int AT_WITHIN_VAR = 6;
static final int AT_WITHINCODE_VAR = 7;
static final int AT_ANNOTATION_VAR = 8;
static final int AT_ARGS_PARAM_ANNO_VAR = 9;
private AnnotationFinder annotationFinder = null;
// static {
// try {
// Class java15AnnotationFinder = Class.forName("org.aspectj.weaver.reflect.Java15AnnotationFinder");
// annotationFinder = (AnnotationFinder) java15AnnotationFinder.newInstance();
// } catch(ClassNotFoundException ex) {
// // must be on 1.4 or earlier
// } catch(IllegalAccessException ex) {
// // not so good
// throw new RuntimeException("AspectJ internal error",ex);
// } catch(InstantiationException ex) {
// throw new RuntimeException("AspectJ internal error",ex);
// }
// }
private int argsIndex = 0;
private int paramAnnoIndex;
private int varType;
public static ReflectionVar createThisVar(ResolvedType type,AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = THIS_VAR;
return ret;
}
public static ReflectionVar createTargetVar(ResolvedType type, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = TARGET_VAR;
return ret;
}
public static ReflectionVar createArgsVar(ResolvedType type, int index, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = ARGS_VAR;
ret.argsIndex = index;
return ret;
}
public static ReflectionVar createThisAnnotationVar(ResolvedType type, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = AT_THIS_VAR;
return ret;
}
public static ReflectionVar createTargetAnnotationVar(ResolvedType type, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = AT_TARGET_VAR;
return ret;
}
public static ReflectionVar createArgsAnnotationVar(ResolvedType type, int index, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = AT_ARGS_VAR;
ret.argsIndex = index;
return ret;
}
public static ReflectionVar createArgsParamAnnotationVar(ResolvedType type, int index, int paramAnnoIndex, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(type,finder);
ret.varType = AT_ARGS_PARAM_ANNO_VAR;
ret.argsIndex = index;
ret.paramAnnoIndex = paramAnnoIndex;
return ret;
}
public static ReflectionVar createWithinAnnotationVar(ResolvedType annType, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(annType,finder);
ret.varType = AT_WITHIN_VAR;
return ret;
}
public static ReflectionVar createWithinCodeAnnotationVar(ResolvedType annType, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(annType,finder);
ret.varType = AT_WITHINCODE_VAR;
return ret;
}
public static ReflectionVar createAtAnnotationVar(ResolvedType annType, AnnotationFinder finder) {
ReflectionVar ret = new ReflectionVar(annType,finder);
ret.varType = AT_ANNOTATION_VAR;
return ret;
}
private ReflectionVar(ResolvedType type, AnnotationFinder finder) {
super(type);
this.annotationFinder = finder;
}
public Object getBindingAtJoinPoint(Object thisObject, Object targetObject, Object[] args) {
return getBindingAtJoinPoint(thisObject,targetObject,args,null,null,null);
}
/**
* At a join point with the given this, target, and args, return the object to which this
* var is bound.
*
* @param thisObject
* @param targetObject
* @param args
* @return
*/
public Object getBindingAtJoinPoint(
Object thisObject,
Object targetObject,
Object[] args,
Member subject,
Member withinCode,
Class withinType) {
switch( this.varType) {
case THIS_VAR: return thisObject;
case TARGET_VAR: return targetObject;
case ARGS_VAR:
if (this.argsIndex > (args.length - 1)) return null;
return args[argsIndex];
case AT_THIS_VAR:
if (annotationFinder != null) {
return annotationFinder.getAnnotation(getType(), thisObject);
} else return null;
case AT_TARGET_VAR:
if (annotationFinder != null) {
return annotationFinder.getAnnotation(getType(), targetObject);
} else return null;
case AT_ARGS_VAR:
if (this.argsIndex > (args.length - 1)) return null;
if (annotationFinder != null) {
return annotationFinder.getAnnotation(getType(), args[argsIndex]);
} else return null;
case AT_ARGS_PARAM_ANNO_VAR:
if (this.argsIndex > (args.length - 1)) return null;
if (annotationFinder != null) {
return annotationFinder.getParamAnnotation(subject, argsIndex, paramAnnoIndex);
} else return null;
case AT_WITHIN_VAR:
if (annotationFinder != null) {
return annotationFinder.getAnnotationFromClass(getType(), withinType);
} else return null;
case AT_WITHINCODE_VAR:
if (annotationFinder != null) {
return annotationFinder.getAnnotationFromMember(getType(), withinCode);
} else return null;
case AT_ANNOTATION_VAR:
if (annotationFinder != null) {
return annotationFinder.getAnnotationFromMember(getType(), subject);
} else return null;
}
return null;
}
}
|