~ubuntu-branches/ubuntu/wily/aspectj/wily-proposed

« back to all changes in this revision

Viewing changes to org.aspectj/modules/org.aspectj.matcher/src/org/aspectj/weaver/reflect/ShadowMatchImpl.java

  • Committer: Bazaar Package Importer
  • Author(s): Damien Raude-Morvan
  • Date: 2011-03-15 23:54:31 UTC
  • mfrom: (1.2.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 9.
  • Revision ID: james.westby@ubuntu.com-20110315235431-iq2gxbsx08kpwuiw
* New upstream release.
* Updated Standards-Version to 3.9.1 (no changes needed).
* Fix local Javadoc links:
  - d/patches/07_javadoc_links.diff: Use locally installed
   javadoc packages and hyperlink with them.
  - d/control: Add B-D on default-java-doc and libasm3-java-doc.
* d/control: Drop B-D on itself (our new bootstrap infrastructure doesn't need
  that anymore).
* Split packages into :
  - aspectj: only contains CLI tools.
  - libaspectj-java: JAR librairies for /usr/share/java.
  - libaspectj-java-doc: 4 API's Javadoc.
  - aspectj-doc: Programming Guides and SDK Documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
import org.aspectj.weaver.tools.ShadowMatch;
37
37
 
38
38
/**
39
 
 * @author colyer
40
 
 * Implementation of ShadowMatch for reflection based worlds.
 
39
 * @author colyer Implementation of ShadowMatch for reflection based worlds.
41
40
 */
42
41
public class ShadowMatchImpl implements ShadowMatch {
43
42
 
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();
52
 
        
 
51
 
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;
58
57
        }
59
 
        
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; }
63
 
                
 
58
 
 
59
        public void setWithinCode(Member aMember) {
 
60
                this.withinCode = aMember;
 
61
        }
 
62
 
 
63
        public void setSubject(Member aMember) {
 
64
                this.subject = aMember;
 
65
        }
 
66
 
 
67
        public void setWithinType(Class<?> aClass) {
 
68
                this.withinType = aClass;
 
69
        }
 
70
 
64
71
        public boolean alwaysMatches() {
65
72
                return match.alwaysTrue();
66
73
        }
74
81
        }
75
82
 
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));
 
84
                if (neverMatches()) {
 
85
                        return JoinPointMatchImpl.NO_MATCH;
 
86
                }
 
87
                if (new RuntimeTestEvaluator(residualTest, thisObject, targetObject, args, this.matchContext).matches()) {
 
88
                        return new JoinPointMatchImpl(getPointcutParameters(thisObject, targetObject, args));
80
89
                } else {
81
90
                        return JoinPointMatchImpl.NO_MATCH;
82
91
                }
83
92
        }
84
 
        
85
 
        /* (non-Javadoc)
 
93
 
 
94
        /*
 
95
         * (non-Javadoc)
 
96
         * 
86
97
         * @see org.aspectj.weaver.tools.ShadowMatch#setMatchingContext(org.aspectj.weaver.tools.MatchingContext)
87
98
         */
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));
98
110
                }
99
111
                return bindings;
100
112
        }
107
119
                private final Object targetObject;
108
120
                private final Object[] args;
109
121
                private final MatchingContext matchContext;
110
 
                
111
 
                
112
 
                public RuntimeTestEvaluator(Test aTest,Object thisObject, Object targetObject, Object[] args, MatchingContext context) {
 
122
 
 
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;
118
129
                }
119
 
                
 
130
 
120
131
                public boolean matches() {
121
132
                        test.accept(this);
122
133
                        return matches;
123
134
                }
124
 
                
 
135
 
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) {
129
139
                                matches = false;
130
140
                        } else {
131
 
                                matches = new RuntimeTestEvaluator(e.getRight(),thisObject,targetObject,args,matchContext).matches();
132
 
                        }                       
 
141
                                matches = new RuntimeTestEvaluator(e.getRight(), thisObject, targetObject, args, matchContext).matches();
 
142
                        }
133
143
                }
134
144
 
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);
 
150
                        if (value == null) {
 
151
                                matches = false;
 
152
                        } else {
 
153
                                ResolvedType actualType = world.resolve(value.getClass().getName());
 
154
                                matches = desiredType.isAssignableFrom(actualType);
 
155
                        }
142
156
                }
143
 
                
 
157
 
144
158
                public void visit(MatchingContextBasedTest matchingContextTest) {
145
159
                        matches = matchingContextTest.matches(this.matchContext);
146
160
                }
147
161
 
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();
150
164
                }
151
165
 
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) {
156
169
                                matches = true;
157
170
                        } else {
158
 
                                matches = new RuntimeTestEvaluator(or.getRight(),thisObject,targetObject,args,matchContext).matches();
 
171
                                matches = new RuntimeTestEvaluator(or.getRight(), thisObject, targetObject, args, matchContext).matches();
159
172
                        }
160
173
                }
161
174
 
172
185
                }
173
186
 
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");
176
189
                }
177
190
 
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);
185
198
                }
186
 
                
 
199
 
187
200
        }
188
201
 
189
202
}