47
46
private PointcutParameter[] params;
48
47
private Member withinCode;
49
48
private Member subject;
50
private Class withinType;
49
private Class<?> withinType;
51
50
private MatchingContext matchContext = new DefaultMatchingContext();
53
52
public ShadowMatchImpl(FuzzyBoolean match, Test test, ExposedState state, PointcutParameter[] params) {
54
53
this.match = match;
55
54
this.residualTest = test;
56
55
this.state = state;
57
56
this.params = params;
60
public void setWithinCode(Member aMember) { this.withinCode = aMember; }
61
public void setSubject(Member aMember) { this.subject = aMember; }
62
public void setWithinType(Class aClass) { this.withinType = aClass; }
59
public void setWithinCode(Member aMember) {
60
this.withinCode = aMember;
63
public void setSubject(Member aMember) {
64
this.subject = aMember;
67
public void setWithinType(Class<?> aClass) {
68
this.withinType = aClass;
64
71
public boolean alwaysMatches() {
65
72
return match.alwaysTrue();
76
83
public JoinPointMatch matchesJoinPoint(Object thisObject, Object targetObject, Object[] args) {
77
if (neverMatches()) return JoinPointMatchImpl.NO_MATCH;
78
if (new RuntimeTestEvaluator(residualTest,thisObject,targetObject,args,this.matchContext).matches()) {
79
return new JoinPointMatchImpl(getPointcutParameters(thisObject,targetObject,args));
85
return JoinPointMatchImpl.NO_MATCH;
87
if (new RuntimeTestEvaluator(residualTest, thisObject, targetObject, args, this.matchContext).matches()) {
88
return new JoinPointMatchImpl(getPointcutParameters(thisObject, targetObject, args));
81
90
return JoinPointMatchImpl.NO_MATCH;
86
97
* @see org.aspectj.weaver.tools.ShadowMatch#setMatchingContext(org.aspectj.weaver.tools.MatchingContext)
88
99
public void setMatchingContext(MatchingContext aMatchContext) {
93
104
Var[] vars = state.vars;
94
105
PointcutParameterImpl[] bindings = new PointcutParameterImpl[params.length];
95
106
for (int i = 0; i < bindings.length; i++) {
96
bindings[i] = new PointcutParameterImpl(params[i].getName(),params[i].getType());
97
bindings[i].setBinding(((ReflectionVar)vars[i]).getBindingAtJoinPoint(thisObject, targetObject, args,subject,withinCode,withinType));
107
bindings[i] = new PointcutParameterImpl(params[i].getName(), params[i].getType());
108
bindings[i].setBinding(((ReflectionVar) vars[i]).getBindingAtJoinPoint(thisObject, targetObject, args, subject,
109
withinCode, withinType));
107
119
private final Object targetObject;
108
120
private final Object[] args;
109
121
private final MatchingContext matchContext;
112
public RuntimeTestEvaluator(Test aTest,Object thisObject, Object targetObject, Object[] args, MatchingContext context) {
123
public RuntimeTestEvaluator(Test aTest, Object thisObject, Object targetObject, Object[] args, MatchingContext context) {
113
124
this.test = aTest;
114
125
this.thisObject = thisObject;
115
126
this.targetObject = targetObject;
116
127
this.args = args;
117
128
this.matchContext = context;
120
131
public boolean matches() {
121
132
test.accept(this);
125
136
public void visit(And e) {
126
boolean leftMatches =
127
new RuntimeTestEvaluator(e.getLeft(),thisObject,targetObject,args,matchContext).matches();
137
boolean leftMatches = new RuntimeTestEvaluator(e.getLeft(), thisObject, targetObject, args, matchContext).matches();
128
138
if (!leftMatches) {
131
matches = new RuntimeTestEvaluator(e.getRight(),thisObject,targetObject,args,matchContext).matches();
141
matches = new RuntimeTestEvaluator(e.getRight(), thisObject, targetObject, args, matchContext).matches();
135
public void visit(Instanceof i) {
136
ReflectionVar v = (ReflectionVar) i.getVar();
137
Object value = v.getBindingAtJoinPoint(thisObject,targetObject, args);
145
public void visit(Instanceof instanceofTest) {
146
ReflectionVar v = (ReflectionVar) instanceofTest.getVar();
147
Object value = v.getBindingAtJoinPoint(thisObject, targetObject, args);
138
148
World world = v.getType().getWorld();
139
ResolvedType desiredType = i.getType().resolve(world);
140
ResolvedType actualType = world.resolve(value.getClass().getName());
141
matches = desiredType.isAssignableFrom(actualType);
149
ResolvedType desiredType = instanceofTest.getType().resolve(world);
153
ResolvedType actualType = world.resolve(value.getClass().getName());
154
matches = desiredType.isAssignableFrom(actualType);
144
158
public void visit(MatchingContextBasedTest matchingContextTest) {
145
159
matches = matchingContextTest.matches(this.matchContext);
148
162
public void visit(Not not) {
149
matches = ! new RuntimeTestEvaluator(not.getBody(),thisObject,targetObject,args,matchContext).matches();
163
matches = !new RuntimeTestEvaluator(not.getBody(), thisObject, targetObject, args, matchContext).matches();
152
166
public void visit(Or or) {
153
boolean leftMatches =
154
new RuntimeTestEvaluator(or.getLeft(),thisObject,targetObject,args,matchContext).matches();
167
boolean leftMatches = new RuntimeTestEvaluator(or.getLeft(), thisObject, targetObject, args, matchContext).matches();
155
168
if (leftMatches) {
158
matches = new RuntimeTestEvaluator(or.getRight(),thisObject,targetObject,args,matchContext).matches();
171
matches = new RuntimeTestEvaluator(or.getRight(), thisObject, targetObject, args, matchContext).matches();
174
187
public void visit(FieldGetCall fieldGetCall) {
175
throw new UnsupportedOperationException("Can't evaluate fieldGetCall test at runtime");
188
throw new UnsupportedOperationException("Can't evaluate fieldGetCall test at runtime");
178
191
public void visit(HasAnnotation hasAnnotation) {
179
192
ReflectionVar v = (ReflectionVar) hasAnnotation.getVar();
180
Object value = v.getBindingAtJoinPoint(thisObject,targetObject, args);
193
Object value = v.getBindingAtJoinPoint(thisObject, targetObject, args);
181
194
World world = v.getType().getWorld();
182
195
ResolvedType actualVarType = world.resolve(value.getClass().getName());
183
196
ResolvedType requiredAnnotationType = hasAnnotation.getAnnotationType().resolve(world);
184
197
matches = actualVarType.hasAnnotation(requiredAnnotationType);