OLD | NEW |
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 mirror_system_helper; | 5 library mirror_system_helper; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'package:compiler/src/mirrors/source_mirrors.dart'; | 8 import 'package:compiler/src/mirrors/source_mirrors.dart'; |
9 import 'package:compiler/src/mirrors/dart2js_mirrors.dart'; | 9 import 'package:compiler/src/mirrors/dart2js_mirrors.dart'; |
10 import 'mock_compiler.dart'; | 10 import 'mock_compiler.dart'; |
11 | 11 |
12 export 'package:compiler/src/mirrors/source_mirrors.dart'; | 12 export 'package:compiler/src/mirrors/source_mirrors.dart'; |
13 export 'package:compiler/src/mirrors/mirrors_util.dart'; | 13 export 'package:compiler/src/mirrors/mirrors_util.dart'; |
14 | 14 |
15 const String SOURCE = 'source'; | 15 const String SOURCE = 'source'; |
16 final Uri SOURCE_URI = new Uri(scheme: SOURCE, path: SOURCE); | 16 final Uri SOURCE_URI = new Uri(scheme: SOURCE, path: SOURCE); |
17 | 17 |
18 // TODO(johnniwinther): Move this to a mirrors helper library. | 18 // TODO(johnniwinther): Move this to a mirrors helper library. |
19 Future<MirrorSystem> createMirrorSystem(String source) { | 19 Future<MirrorSystem> createMirrorSystem(String source) { |
20 MockCompiler compiler = new MockCompiler.internal( | 20 MockCompiler compiler = new MockCompiler.internal( |
21 analyzeOnly: true, | 21 analyzeOnly: true, |
22 analyzeAll: true, | 22 analyzeAll: true, |
23 preserveComments: true); | 23 preserveComments: true); |
24 compiler.registerSource(SOURCE_URI, source); | 24 compiler.registerSource(SOURCE_URI, source); |
25 compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI]; | 25 compiler.librariesToAnalyzeWhenRun = <Uri>[SOURCE_URI]; |
26 return compiler.runCompiler(null).then((_) { | 26 return compiler.run(null).then((_) { |
27 return new Dart2JsMirrorSystem(compiler); | 27 return new Dart2JsMirrorSystem(compiler); |
28 }); | 28 }); |
29 } | 29 } |
30 | 30 |
31 /** | 31 /** |
32 * Returns [:true:] if [type] is an instance of [:decl:] with type arguments | 32 * Returns [:true:] if [type] is an instance of [:decl:] with type arguments |
33 * equal to [typeArgument]. | 33 * equal to [typeArgument]. |
34 */ | 34 */ |
35 bool isInstance(ClassMirror decl, List<TypeMirror> typeArguments, | 35 bool isInstance(ClassMirror decl, List<TypeMirror> typeArguments, |
36 ClassMirror type) { | 36 ClassMirror type) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 if (expected.length != types.length) return false; | 130 if (expected.length != types.length) return false; |
131 Iterator<TypeMirror> expectedIterator = expected.iterator; | 131 Iterator<TypeMirror> expectedIterator = expected.iterator; |
132 Iterator<TypeMirror> typesIterator = types.iterator; | 132 Iterator<TypeMirror> typesIterator = types.iterator; |
133 while (expectedIterator.moveNext() && typesIterator.moveNext()) { | 133 while (expectedIterator.moveNext() && typesIterator.moveNext()) { |
134 if (!check(expectedIterator.current, typesIterator.current)) { | 134 if (!check(expectedIterator.current, typesIterator.current)) { |
135 return false; | 135 return false; |
136 } | 136 } |
137 } | 137 } |
138 return true; | 138 return true; |
139 } | 139 } |
OLD | NEW |