Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(453)

Side by Side Diff: dart/tests/compiler/dart2js/mirrors_lookup_test.dart

Issue 21110003: Implement MirrorUsed.targets for libraries (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Merged with r25609 and added test. Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library dart2js.test.memory_source_file_helper; 5 library dart2js.test.memory_source_file_helper;
6 6
7 import 'package:expect/expect.dart'; 7 import 'package:expect/expect.dart';
8 import 'memory_compiler.dart'; 8 import 'memory_compiler.dart';
9 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ; 9 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart' ;
10 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart'; 10 import '../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_util. dart';
(...skipping 23 matching lines...) Expand all
34 34
35 void main() { 35 void main() {
36 mirrorSystemFor(MEMORY_SOURCE_FILES).then( 36 mirrorSystemFor(MEMORY_SOURCE_FILES).then(
37 (MirrorSystem mirrors) => test(mirrors), 37 (MirrorSystem mirrors) => test(mirrors),
38 onError: (e) => Expect.fail('$e')); 38 onError: (e) => Expect.fail('$e'));
39 } 39 }
40 40
41 void test(MirrorSystem mirrors) { 41 void test(MirrorSystem mirrors) {
42 LibraryMirror dartCore = mirrors.libraries[Uri.parse('dart:core')]; 42 LibraryMirror dartCore = mirrors.libraries[Uri.parse('dart:core')];
43 Expect.isNotNull(dartCore); 43 Expect.isNotNull(dartCore);
44 44
45 LibraryMirror dartAsync = mirrors.libraries[Uri.parse('dart:async')]; 45 LibraryMirror dartAsync = mirrors.libraries[Uri.parse('dart:async')];
46 Expect.isNotNull(dartAsync); 46 Expect.isNotNull(dartAsync);
47 47
48 LibraryMirror library = mirrors.libraries[Uri.parse('memory:main.dart')]; 48 LibraryMirror library = mirrors.libraries[Uri.parse('memory:main.dart')];
49 Expect.isNotNull(library); 49 Expect.isNotNull(library);
50 50
51 // Check top-level scope. 51 // Check top-level scope.
52 52
53 DeclarationMirror String_ = library.lookupInScope('String'); 53 DeclarationMirror String_ = library.lookupInScope('String');
54 Expect.isTrue(String_ is ClassMirror); 54 Expect.isTrue(String_ is ClassMirror);
55 Expect.equals('String', String_.simpleName); 55 Expect.equals('String', String_.simpleName);
56 Expect.equals(dartCore, String_.owner); 56 Expect.equals(dartCore, String_.owner);
57 57
58 Expect.isNull(library.lookupInScope('async')); 58 Expect.isNull(library.lookupInScope('async'));
59 Expect.isNull(library.lookupInScope('Future')); 59 Expect.isNull(library.lookupInScope('Future'));
60 DeclarationMirror Future_ = library.lookupInScope('async.Future'); 60 DeclarationMirror Future_ = library.lookupInScope('async.Future');
61 Expect.isTrue(Future_ is ClassMirror); 61 Expect.isTrue(Future_ is ClassMirror);
62 Expect.equals('Future', Future_.simpleName); 62 Expect.equals('Future', Future_.simpleName);
63 Expect.equals(dartAsync, Future_.owner); 63 Expect.equals(dartAsync, Future_.owner);
64 // Timer is not in scope. 64 // Timer is not in scope.
65 Expect.isNull(library.lookupInScope('Timer')); 65 Expect.isNull(library.lookupInScope('Timer'));
66 // async.Timer is hidden. 66 // async.Timer is hidden.
67 Expect.isNull(library.lookupInScope('async.Timer')); 67 Expect.isNull(library.lookupInScope('async.Timer'));
68 68
69 DeclarationMirror variable = library.lookupInScope('variable'); 69 DeclarationMirror variable = library.lookupInScope('variable');
70 Expect.isTrue(variable is VariableMirror); 70 Expect.isTrue(variable is VariableMirror);
71 Expect.equals('variable', variable.simpleName); 71 Expect.equals('variable', variable.simpleName);
72 Expect.equals('main.variable', variable.qualifiedName); 72 Expect.equals('main.variable', variable.qualifiedName);
73 Expect.equals(library, variable.owner); 73 Expect.equals(library, variable.owner);
74 // Parameter `a` is not in scope. 74 // Parameter `a` is not in scope.
75 Expect.isNull(library.lookupInScope('a')); 75 Expect.isNull(library.lookupInScope('a'));
76 // Parameter `b` is not in scope. 76 // Parameter `b` is not in scope.
77 Expect.isNull(library.lookupInScope('b')); 77 Expect.isNull(library.lookupInScope('b'));
78 78
79 DeclarationMirror method = library.lookupInScope('method'); 79 DeclarationMirror method = library.lookupInScope('method');
80 Expect.isTrue(method is MethodMirror); 80 Expect.isTrue(method is MethodMirror);
81 Expect.equals('method', method.simpleName); 81 Expect.equals('method', method.simpleName);
82 Expect.equals('main.method', method.qualifiedName); 82 Expect.equals('main.method', method.qualifiedName);
83 Expect.equals(library, method.owner); 83 Expect.equals(library, method.owner);
84 84
85 DeclarationMirror Class = library.lookupInScope('Class'); 85 DeclarationMirror Class = library.lookupInScope('Class');
86 Expect.isTrue(Class is ClassMirror); 86 Expect.isTrue(Class is ClassMirror);
87 Expect.equals('Class', Class.simpleName); 87 Expect.equals('Class', Class.simpleName);
88 Expect.equals('main.Class', Class.qualifiedName); 88 Expect.equals('main.Class', Class.qualifiedName);
89 Expect.equals(library, Class.owner); 89 Expect.equals(library, Class.owner);
90 // Type variable `A` is not in scope. 90 // Type variable `A` is not in scope.
91 Expect.isNull(library.lookupInScope('A')); 91 Expect.isNull(library.lookupInScope('A'));
92 92
93 DeclarationMirror Subclass = library.lookupInScope('Subclass'); 93 DeclarationMirror Subclass = library.lookupInScope('Subclass');
94 Expect.isTrue(Subclass is ClassMirror); 94 Expect.isTrue(Subclass is ClassMirror);
95 Expect.equals('Subclass', Subclass.simpleName); 95 Expect.equals('Subclass', Subclass.simpleName);
96 Expect.equals('main.Subclass', Subclass.qualifiedName); 96 Expect.equals('main.Subclass', Subclass.qualifiedName);
97 Expect.equals(library, Subclass.owner); 97 Expect.equals(library, Subclass.owner);
98 // Type variable `B` is not in scope. 98 // Type variable `B` is not in scope.
99 Expect.isNull(library.lookupInScope('B')); 99 Expect.isNull(library.lookupInScope('B'));
100 100
101 // Check top-level declaration scope. 101 // Check top-level declaration scope.
102 checkTopScope(DeclarationMirror declaration) { 102 checkTopScope(DeclarationMirror declaration) {
103 Expect.equals(String_, declaration.lookupInScope('String')); 103 Expect.equals(String_, declaration.lookupInScope('String'));
104 Expect.equals(Future_, declaration.lookupInScope('async.Future')); 104 Expect.equals(Future_, declaration.lookupInScope('async.Future'));
105 Expect.isNull(method.lookupInScope('Timer')); 105 Expect.isNull(method.lookupInScope('Timer'));
106 Expect.isNull(declaration.lookupInScope('async.Timer')); 106 Expect.isNull(declaration.lookupInScope('async.Timer'));
107 Expect.equals(variable, declaration.lookupInScope('variable')); 107 Expect.equals(variable, declaration.lookupInScope('variable'));
108 Expect.equals(method, declaration.lookupInScope('method')); 108 Expect.equals(method, declaration.lookupInScope('method'));
109 Expect.equals(Class, declaration.lookupInScope('Class')); 109 Expect.equals(Class, declaration.lookupInScope('Class'));
110 // Type variable `A` is not in scope. 110 // Type variable `A` is not in scope.
111 Expect.isNull(declaration.lookupInScope('A')); 111 Expect.isNull(declaration.lookupInScope('A'));
112 // Field `field` is not in scope. 112 // Field `field` is not in scope.
113 Expect.isNull(declaration.lookupInScope('field')); 113 Expect.isNull(declaration.lookupInScope('field'));
114 Expect.equals(Subclass, declaration.lookupInScope('Subclass')); 114 Expect.equals(Subclass, declaration.lookupInScope('Subclass'));
115 // Type variable `B` is not in scope. 115 // Type variable `B` is not in scope.
116 Expect.isNull(declaration.lookupInScope('B')); 116 Expect.isNull(declaration.lookupInScope('B'));
117 // Field `subfield` is not in scope. 117 // Field `subfield` is not in scope.
118 Expect.isNull(declaration.lookupInScope('subfield')); 118 Expect.isNull(declaration.lookupInScope('subfield'));
119 } 119 }
120 120
121 checkTopScope(variable); 121 checkTopScope(variable);
122 // Parameter `a` is not in scope of `variable`. 122 // Parameter `a` is not in scope of `variable`.
123 Expect.isNull(variable.lookupInScope('a')); 123 Expect.isNull(variable.lookupInScope('a'));
124 // Parameter `b` is not in scope of `variable`. 124 // Parameter `b` is not in scope of `variable`.
125 Expect.isNull(variable.lookupInScope('b')); 125 Expect.isNull(variable.lookupInScope('b'));
126 126
127 checkTopScope(method); 127 checkTopScope(method);
128 // Parameter `a` is in scope of `method`. 128 // Parameter `a` is in scope of `method`.
129 Expect.isTrue(method.lookupInScope('a') is ParameterMirror); 129 Expect.isTrue(method.lookupInScope('a') is ParameterMirror);
130 // Parameter `b` is in scope of `method`. 130 // Parameter `b` is in scope of `method`.
131 Expect.isTrue(method.lookupInScope('b') is ParameterMirror); 131 Expect.isTrue(method.lookupInScope('b') is ParameterMirror);
132 132
133 // Check class scope. 133 // Check class scope.
134 DeclarationMirror Class_field = Class.lookupInScope('field'); 134 DeclarationMirror Class_field = Class.lookupInScope('field');
135 Expect.isTrue(Class_field is VariableMirror); 135 Expect.isTrue(Class_field is VariableMirror);
136 Expect.notEquals(variable, Class_field); 136 Expect.notEquals(variable, Class_field);
137 Expect.equals(Class, Class_field.owner); 137 Expect.equals(Class, Class_field.owner);
138 138
139 DeclarationMirror Class_variable = Class.lookupInScope('variable'); 139 DeclarationMirror Class_variable = Class.lookupInScope('variable');
140 Expect.isTrue(Class_variable is VariableMirror); 140 Expect.isTrue(Class_variable is VariableMirror);
141 Expect.notEquals(variable, Class_variable); 141 Expect.notEquals(variable, Class_variable);
142 Expect.equals(Class, Class_variable.owner); 142 Expect.equals(Class, Class_variable.owner);
143 143
144 DeclarationMirror Class_method = Class.lookupInScope('method'); 144 DeclarationMirror Class_method = Class.lookupInScope('method');
145 Expect.isTrue(Class_method is MethodMirror); 145 Expect.isTrue(Class_method is MethodMirror);
146 Expect.notEquals(method, Class_method); 146 Expect.notEquals(method, Class_method);
147 Expect.equals(Class, Class_method.owner); 147 Expect.equals(Class, Class_method.owner);
148 148
149 checkClassScope(DeclarationMirror declaration, {bool parametersInScope}) { 149 checkClassScope(DeclarationMirror declaration, {bool parametersInScope}) {
150 Expect.equals(String_, declaration.lookupInScope('String')); 150 Expect.equals(String_, declaration.lookupInScope('String'));
151 Expect.equals(Future_, declaration.lookupInScope('async.Future')); 151 Expect.equals(Future_, declaration.lookupInScope('async.Future'));
152 Expect.isNull(declaration.lookupInScope('Timer')); 152 Expect.isNull(declaration.lookupInScope('Timer'));
153 Expect.isNull(declaration.lookupInScope('async.Timer')); 153 Expect.isNull(declaration.lookupInScope('async.Timer'));
154 154
155 Expect.equals(Class_field, declaration.lookupInScope('field')); 155 Expect.equals(Class_field, declaration.lookupInScope('field'));
156 Expect.equals(Class_variable, declaration.lookupInScope('variable')); 156 Expect.equals(Class_variable, declaration.lookupInScope('variable'));
157 Expect.equals(Class_method, declaration.lookupInScope('method')); 157 Expect.equals(Class_method, declaration.lookupInScope('method'));
158 158
159 // Parameter `a` is not in scope. 159 // Parameter `a` is not in scope.
160 Expect.isNull(declaration.lookupInScope('a')); 160 Expect.isNull(declaration.lookupInScope('a'));
161 // Parameter `b` is not in scope. 161 // Parameter `b` is not in scope.
162 Expect.isNull(declaration.lookupInScope('b')); 162 Expect.isNull(declaration.lookupInScope('b'));
163 163
164 if (parametersInScope) { 164 if (parametersInScope) {
165 // Parameter `c` is in scope. 165 // Parameter `c` is in scope.
166 Expect.isTrue(declaration.lookupInScope('c') is ParameterMirror); 166 Expect.isTrue(declaration.lookupInScope('c') is ParameterMirror);
167 // Parameter `d` is in scope. 167 // Parameter `d` is in scope.
168 Expect.isTrue(declaration.lookupInScope('d') is ParameterMirror); 168 Expect.isTrue(declaration.lookupInScope('d') is ParameterMirror);
169 } else { 169 } else {
170 // Parameter `c` is not in scope. 170 // Parameter `c` is not in scope.
171 Expect.isNull(declaration.lookupInScope('c')); 171 Expect.isNull(declaration.lookupInScope('c'));
172 // Parameter `d` is not in scope. 172 // Parameter `d` is not in scope.
173 Expect.isNull(declaration.lookupInScope('d')); 173 Expect.isNull(declaration.lookupInScope('d'));
174 } 174 }
175 175
176 Expect.equals(Class, declaration.lookupInScope('Class')); 176 Expect.equals(Class, declaration.lookupInScope('Class'));
177 // Type variable `A` is in scope. 177 // Type variable `A` is in scope.
178 Expect.isTrue(declaration.lookupInScope('A') is TypeVariableMirror); 178 Expect.isTrue(declaration.lookupInScope('A') is TypeVariableMirror);
179 Expect.equals(Subclass, declaration.lookupInScope('Subclass')); 179 Expect.equals(Subclass, declaration.lookupInScope('Subclass'));
180 // Type variable `B` is not in scope. 180 // Type variable `B` is not in scope.
181 Expect.isNull(declaration.lookupInScope('B')); 181 Expect.isNull(declaration.lookupInScope('B'));
182 // Field `subfield` is not in scope. 182 // Field `subfield` is not in scope.
183 Expect.isNull(declaration.lookupInScope('subfield')); 183 Expect.isNull(declaration.lookupInScope('subfield'));
184 } 184 }
185 checkClassScope(Class, parametersInScope: false); 185 checkClassScope(Class, parametersInScope: false);
186 checkClassScope(Class_field, parametersInScope: false); 186 checkClassScope(Class_field, parametersInScope: false);
187 checkClassScope(Class_variable, parametersInScope: false); 187 checkClassScope(Class_variable, parametersInScope: false);
188 checkClassScope(Class_method, parametersInScope: true); 188 checkClassScope(Class_method, parametersInScope: true);
189 189
190 // Check class scope. 190 // Check class scope.
191 DeclarationMirror Subclass_subfield = Subclass.lookupInScope('subfield'); 191 DeclarationMirror Subclass_subfield = Subclass.lookupInScope('subfield');
192 Expect.isTrue(Subclass_subfield is VariableMirror); 192 Expect.isTrue(Subclass_subfield is VariableMirror);
193 Expect.notEquals(variable, Subclass_subfield); 193 Expect.notEquals(variable, Subclass_subfield);
194 Expect.equals(Subclass, Subclass_subfield.owner); 194 Expect.equals(Subclass, Subclass_subfield.owner);
195 195
196 checkSubclassScope(DeclarationMirror declaration) { 196 checkSubclassScope(DeclarationMirror declaration) {
197 Expect.equals(String_, declaration.lookupInScope('String')); 197 Expect.equals(String_, declaration.lookupInScope('String'));
198 Expect.equals(Future_, declaration.lookupInScope('async.Future')); 198 Expect.equals(Future_, declaration.lookupInScope('async.Future'));
199 Expect.isNull(declaration.lookupInScope('Timer')); 199 Expect.isNull(declaration.lookupInScope('Timer'));
200 Expect.isNull(declaration.lookupInScope('async.Timer')); 200 Expect.isNull(declaration.lookupInScope('async.Timer'));
201 201
202 // Top level `variable` is in scope. 202 // Top level `variable` is in scope.
203 Expect.equals(variable, declaration.lookupInScope('variable')); 203 Expect.equals(variable, declaration.lookupInScope('variable'));
204 // Top level `method` is in scope. 204 // Top level `method` is in scope.
205 Expect.equals(method, declaration.lookupInScope('method')); 205 Expect.equals(method, declaration.lookupInScope('method'));
206 206
207 // Parameter `a` is not in scope 207 // Parameter `a` is not in scope
208 Expect.isNull(declaration.lookupInScope('a')); 208 Expect.isNull(declaration.lookupInScope('a'));
209 // Parameter `b` is not in scope 209 // Parameter `b` is not in scope
210 Expect.isNull(declaration.lookupInScope('b')); 210 Expect.isNull(declaration.lookupInScope('b'));
211 211
212 // Parameter `c` is not in scope. 212 // Parameter `c` is not in scope.
213 Expect.isNull(declaration.lookupInScope('c')); 213 Expect.isNull(declaration.lookupInScope('c'));
214 // Parameter `d` is not in scope. 214 // Parameter `d` is not in scope.
215 Expect.isNull(declaration.lookupInScope('d')); 215 Expect.isNull(declaration.lookupInScope('d'));
216 216
217 Expect.equals(Class, declaration.lookupInScope('Class')); 217 Expect.equals(Class, declaration.lookupInScope('Class'));
218 // Type variable `A` is not in scope 218 // Type variable `A` is not in scope
219 Expect.isNull(declaration.lookupInScope('A')); 219 Expect.isNull(declaration.lookupInScope('A'));
220 // Field `field` is in scope 220 // Field `field` is in scope
221 Expect.equals(Class_field, declaration.lookupInScope('field')); 221 Expect.equals(Class_field, declaration.lookupInScope('field'));
222 Expect.equals(Subclass, declaration.lookupInScope('Subclass')); 222 Expect.equals(Subclass, declaration.lookupInScope('Subclass'));
223 // Type variable `B` is in scope 223 // Type variable `B` is in scope
224 Expect.isTrue(declaration.lookupInScope('B') is TypeVariableMirror); 224 Expect.isTrue(declaration.lookupInScope('B') is TypeVariableMirror);
225 // Field `subfield` is in scope 225 // Field `subfield` is in scope
226 Expect.equals(Subclass_subfield, declaration.lookupInScope('subfield')); 226 Expect.equals(Subclass_subfield, declaration.lookupInScope('subfield'));
227 } 227 }
228 checkSubclassScope(Subclass); 228 checkSubclassScope(Subclass);
229 checkSubclassScope(Subclass_subfield); 229 checkSubclassScope(Subclass_subfield);
230 230
231 // `Timer` is in scope of `Future`. 231 // `Timer` is in scope of `Future`.
232 Expect.isTrue(Future_.lookupInScope('Timer') is ClassMirror); 232 Expect.isTrue(Future_.lookupInScope('Timer') is ClassMirror);
233 233
234 // Check qualified lookup. 234 // Check qualified lookup.
235 Expect.equals(variable, lookupQualifiedInScope(library, 'variable')); 235 Expect.equals(variable, lookupQualifiedInScope(library, 'variable'));
236 Expect.equals(method, lookupQualifiedInScope(library, 'method')); 236 Expect.equals(method, lookupQualifiedInScope(library, 'method'));
237 Expect.isTrue(lookupQualifiedInScope(library, 'method.a') is ParameterMirror); 237 Expect.isTrue(lookupQualifiedInScope(library, 'method.a') is ParameterMirror);
238 238
239 Expect.equals(Class, lookupQualifiedInScope(library, 'Class')); 239 Expect.equals(Class, lookupQualifiedInScope(library, 'Class'));
240 Expect.isTrue( 240 Expect.isTrue(
241 lookupQualifiedInScope(library, 'Class.A') is TypeVariableMirror); 241 lookupQualifiedInScope(library, 'Class.A') is TypeVariableMirror);
242 242
243 Expect.isNull(library.lookupInScope('Class.field')); 243 Expect.isNull(library.lookupInScope('Class.field'));
244 Expect.equals(Class_field, lookupQualifiedInScope(library, 'Class.field')); 244 Expect.equals(Class_field, lookupQualifiedInScope(library, 'Class.field'));
245 245
246 Expect.equals(Class_method, lookupQualifiedInScope(library, 'Class.method')); 246 Expect.equals(Class_method, lookupQualifiedInScope(library, 'Class.method'));
247 Expect.isTrue( 247 Expect.isTrue(
248 lookupQualifiedInScope(library, 'Class.method.c') is ParameterMirror); 248 lookupQualifiedInScope(library, 'Class.method.c') is ParameterMirror);
249 249
250 // `field` should not be found through the prefix `Subclass`. 250 // `field` should not be found through the prefix `Subclass`.
251 Expect.isNull(lookupQualifiedInScope(library, 'Subclass.field')); 251 Expect.isNull(lookupQualifiedInScope(library, 'Subclass.field'));
252 Expect.equals(Subclass_subfield, 252 Expect.equals(Subclass_subfield,
253 lookupQualifiedInScope(library, 'Subclass.subfield')); 253 lookupQualifiedInScope(library, 'Subclass.subfield'));
254 254
255 Expect.equals(Future_, lookupQualifiedInScope(library, 'async.Future')); 255 Expect.equals(Future_, lookupQualifiedInScope(library, 'async.Future'));
256 Expect.isTrue( 256 Expect.isTrue(
257 lookupQualifiedInScope(library, 'async.Future.then') is MethodMirror); 257 lookupQualifiedInScope(library, 'async.Future.then') is MethodMirror);
258 // `Timer` should not be found through the prefix `async.Future`. 258 // `Timer` should not be found through the prefix `async.Future`.
259 Expect.isNull( 259 Expect.isNull(
260 lookupQualifiedInScope(library, 'async.Future.Timer')); 260 lookupQualifiedInScope(library, 'async.Future.Timer'));
261 } 261 }
262
263
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698