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 dart._js_mirrors; | 5 library dart._js_mirrors; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection' show UnmodifiableListView; | 8 import 'dart:collection' show UnmodifiableListView; |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 Map<Uri, LibraryMirror> result = new Map(); | 69 Map<Uri, LibraryMirror> result = new Map(); |
70 for (List<LibraryMirror> list in librariesByName.values) { | 70 for (List<LibraryMirror> list in librariesByName.values) { |
71 for (LibraryMirror library in list) { | 71 for (LibraryMirror library in list) { |
72 result[library.uri] = library; | 72 result[library.uri] = library; |
73 } | 73 } |
74 } | 74 } |
75 return _cachedLibraries = | 75 return _cachedLibraries = |
76 new UnmodifiableMapView<Uri, LibraryMirror>(result); | 76 new UnmodifiableMapView<Uri, LibraryMirror>(result); |
77 } | 77 } |
78 | 78 |
79 Iterable<LibraryMirror> findLibrary(Symbol libraryName) { | 79 LibraryMirror findLibrary(Symbol libraryName) { |
80 return new UnmodifiableListView<LibraryMirror>( | 80 return librariesByName[n(libraryName)].single; |
81 librariesByName[n(libraryName)]); | |
82 } | 81 } |
83 | 82 |
84 static Map<String, List<LibraryMirror>> computeLibrariesByName() { | 83 static Map<String, List<LibraryMirror>> computeLibrariesByName() { |
85 disableTreeShaking(); | 84 disableTreeShaking(); |
86 var result = new Map<String, List<LibraryMirror>>(); | 85 var result = new Map<String, List<LibraryMirror>>(); |
87 var jsLibraries = JS('JSExtendableArray|Null', 'init.libraries'); | 86 var jsLibraries = JS('JSExtendableArray|Null', 'init.libraries'); |
88 if (jsLibraries == null) return result; | 87 if (jsLibraries == null) return result; |
89 for (List data in jsLibraries) { | 88 for (List data in jsLibraries) { |
90 String name = data[0]; | 89 String name = data[0]; |
91 Uri uri = Uri.parse(data[1]); | 90 Uri uri = Uri.parse(data[1]); |
(...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 Symbol get simpleName { | 621 Symbol get simpleName { |
623 if (_cachedSimpleName != null) return _cachedSimpleName; | 622 if (_cachedSimpleName != null) return _cachedSimpleName; |
624 String superName = n(superclass.qualifiedName); | 623 String superName = n(superclass.qualifiedName); |
625 return _cachedSimpleName = (superName.contains(' with ')) | 624 return _cachedSimpleName = (superName.contains(' with ')) |
626 ? s('$superName, ${n(mixin.qualifiedName)}') | 625 ? s('$superName, ${n(mixin.qualifiedName)}') |
627 : s('$superName with ${n(mixin.qualifiedName)}'); | 626 : s('$superName with ${n(mixin.qualifiedName)}'); |
628 } | 627 } |
629 | 628 |
630 Symbol get qualifiedName => simpleName; | 629 Symbol get qualifiedName => simpleName; |
631 | 630 |
632 Map<Symbol, Mirror> get members => mixin.members; | 631 // TODO(ahe): Remove this method, only here to silence warning. |
| 632 get _mixin => mixin; |
633 | 633 |
634 Map<Symbol, MethodMirror> get methods => mixin.methods; | 634 Map<Symbol, Mirror> get members => _mixin.members; |
635 | 635 |
636 Map<Symbol, MethodMirror> get getters => mixin.getters; | 636 Map<Symbol, MethodMirror> get methods => _mixin.methods; |
637 | 637 |
638 Map<Symbol, MethodMirror> get setters => mixin.setters; | 638 Map<Symbol, MethodMirror> get getters => _mixin.getters; |
639 | 639 |
640 Map<Symbol, VariableMirror> get variables => mixin.variables; | 640 Map<Symbol, MethodMirror> get setters => _mixin.setters; |
| 641 |
| 642 Map<Symbol, VariableMirror> get variables => _mixin.variables; |
| 643 |
| 644 Map<Symbol, DeclarationMirror> get declarations => mixin.declarations; |
641 | 645 |
642 InstanceMirror invoke( | 646 InstanceMirror invoke( |
643 Symbol memberName, | 647 Symbol memberName, |
644 List positionalArguments, | 648 List positionalArguments, |
645 [Map<Symbol,dynamic> namedArguments]) { | 649 [Map<Symbol,dynamic> namedArguments]) { |
646 // TODO(ahe): What receiver to use? | 650 // TODO(ahe): What receiver to use? |
647 throw new NoSuchMethodError(this, memberName, | 651 throw new NoSuchMethodError(this, memberName, |
648 positionalArguments, namedArguments); | 652 positionalArguments, namedArguments); |
649 } | 653 } |
650 | 654 |
651 InstanceMirror getField(Symbol fieldName) { | 655 InstanceMirror getField(Symbol fieldName) { |
652 // TODO(ahe): What receiver to use? | 656 // TODO(ahe): What receiver to use? |
653 throw new NoSuchMethodError(this, fieldName, null, null); | 657 throw new NoSuchMethodError(this, fieldName, null, null); |
654 } | 658 } |
655 | 659 |
656 InstanceMirror setField(Symbol fieldName, Object arg) { | 660 InstanceMirror setField(Symbol fieldName, Object arg) { |
657 // TODO(ahe): What receiver to use? | 661 // TODO(ahe): What receiver to use? |
658 throw new NoSuchMethodError(this, setterSymbol(fieldName), [arg], null); | 662 throw new NoSuchMethodError(this, setterSymbol(fieldName), [arg], null); |
659 } | 663 } |
660 | 664 |
661 List<ClassMirror> get superinterfaces => [mixin]; | 665 List<ClassMirror> get superinterfaces => [mixin]; |
662 | 666 |
663 Map<Symbol, MethodMirror> get constructors => mixin.constructors; | 667 Map<Symbol, MethodMirror> get constructors => _mixin.constructors; |
664 | 668 |
665 InstanceMirror newInstance( | 669 InstanceMirror newInstance( |
666 Symbol constructorName, | 670 Symbol constructorName, |
667 List positionalArguments, | 671 List positionalArguments, |
668 [Map<Symbol,dynamic> namedArguments]) { | 672 [Map<Symbol,dynamic> namedArguments]) { |
669 throw new UnsupportedError( | 673 throw new UnsupportedError( |
670 "Can't instantiate mixin application '${n(qualifiedName)}'"); | 674 "Can't instantiate mixin application '${n(qualifiedName)}'"); |
671 } | 675 } |
672 | 676 |
673 Future<InstanceMirror> newInstanceAsync( | 677 Future<InstanceMirror> newInstanceAsync( |
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2106 | 2110 |
2107 // TODO(ahe): Remove this class and call noSuchMethod instead. | 2111 // TODO(ahe): Remove this class and call noSuchMethod instead. |
2108 class UnimplementedNoSuchMethodError extends Error | 2112 class UnimplementedNoSuchMethodError extends Error |
2109 implements NoSuchMethodError { | 2113 implements NoSuchMethodError { |
2110 final String _message; | 2114 final String _message; |
2111 | 2115 |
2112 UnimplementedNoSuchMethodError(this._message); | 2116 UnimplementedNoSuchMethodError(this._message); |
2113 | 2117 |
2114 String toString() => "Unsupported operation: $_message"; | 2118 String toString() => "Unsupported operation: $_message"; |
2115 } | 2119 } |
OLD | NEW |