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

Side by Side Diff: pkg/compiler/lib/src/mirrors/dart2js_library_mirror.dart

Issue 1335983004: Add ImportElement and ExportElement (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments. Created 5 years, 3 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
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 part of dart2js.mirrors; 5 part of dart2js.mirrors;
6 6
7
8 class Dart2JsLibraryMirror 7 class Dart2JsLibraryMirror
9 extends Dart2JsElementMirror 8 extends Dart2JsElementMirror
10 with ObjectMirrorMixin, ContainerMixin 9 with ObjectMirrorMixin, ContainerMixin
11 implements LibrarySourceMirror { 10 implements LibrarySourceMirror {
12 List<LibraryDependencySourceMirror> _libraryDependencies; 11 List<LibraryDependencySourceMirror> _libraryDependencies;
13 12
14 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) 13 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library)
15 : super(system, library); 14 : super(system, library);
16 15
17 Function operator [](Symbol name) { 16 Function operator [](Symbol name) {
18 throw new UnsupportedError('LibraryMirror.operator [] unsupported.'); 17 throw new UnsupportedError('LibraryMirror.operator [] unsupported.');
19 } 18 }
20 19
21 LibraryElement get _element => super._element; 20 // TODO(johnniwinther): Avoid the need for [LibraryElementX].
21 LibraryElementX get _element => super._element;
22 22
23 Uri get uri => _element.canonicalUri; 23 Uri get uri => _element.canonicalUri;
24 24
25 DeclarationMirror get owner => null; 25 DeclarationMirror get owner => null;
26 26
27 bool get isPrivate => false; 27 bool get isPrivate => false;
28 28
29 LibraryMirror library() => this; 29 LibraryMirror library() => this;
30 30
31 /** 31 /**
32 * Returns the library name (for libraries with a library tag) or the script 32 * Returns the library name (for libraries with a library tag) or the script
33 * file name (for scripts without a library tag). The latter case is used to 33 * file name (for scripts without a library tag). The latter case is used to
34 * provide a 'library name' for scripts, to use for instance in dartdoc. 34 * provide a 'library name' for scripts, to use for instance in dartdoc.
35 */ 35 */
36 String get _simpleNameString => _element.getLibraryOrScriptName(); 36 String get _simpleNameString => _element.libraryOrScriptName;
37 37
38 Symbol get qualifiedName => simpleName; 38 Symbol get qualifiedName => simpleName;
39 39
40 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f); 40 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f);
41 41
42 Iterable<Dart2JsDeclarationMirror> _getDeclarationMirrors(Element element) { 42 Iterable<Dart2JsDeclarationMirror> _getDeclarationMirrors(Element element) {
43 if (element.isClass || element.isTypedef) { 43 if (element.isClass || element.isTypedef) {
44 return [mirrorSystem._getTypeDeclarationMirror(element)]; 44 return [mirrorSystem._getTypeDeclarationMirror(element)];
45 } else { 45 } else {
46 return super._getDeclarationMirrors(element); 46 return super._getDeclarationMirrors(element);
(...skipping 21 matching lines...) Expand all
68 */ 68 */
69 Token getEndToken() { 69 Token getEndToken() {
70 if (!_element.tags.isEmpty) { 70 if (!_element.tags.isEmpty) {
71 return _element.tags.last.getEndToken(); 71 return _element.tags.last.getEndToken();
72 } 72 }
73 return null; 73 return null;
74 } 74 }
75 75
76 void _ensureLibraryDependenciesAnalyzed() { 76 void _ensureLibraryDependenciesAnalyzed() {
77 if (_libraryDependencies == null) { 77 if (_libraryDependencies == null) {
78 // TODO(johnniwinther): Support order of declarations on [LibraryElement].
79 Map<LibraryDependency, Dart2JsLibraryDependencyMirror> mirrorMap =
80 <LibraryDependency, Dart2JsLibraryDependencyMirror>{};
81
82 void addLibraryDependency(LibraryDependency libraryDependency,
83 LibraryElement targetLibraryElement) {
84 assert(targetLibraryElement != null);
85 LibraryMirror targetLibrary =
86 mirrorSystem._getLibrary(targetLibraryElement);
87 mirrorMap[libraryDependency] = new Dart2JsLibraryDependencyMirror(
88 libraryDependency, this, targetLibrary);
89 }
90 for (ImportElement import in _element.imports) {
91 addLibraryDependency(import.node, import.importedLibrary);
92 }
93 for (ExportElement export in _element.exports) {
94 addLibraryDependency(export.node, export.exportedLibrary);
95 }
96
78 _libraryDependencies = <LibraryDependencySourceMirror>[]; 97 _libraryDependencies = <LibraryDependencySourceMirror>[];
98
79 for (LibraryTag node in _element.tags) { 99 for (LibraryTag node in _element.tags) {
80 LibraryDependency libraryDependency = node.asLibraryDependency(); 100 LibraryDependency libraryDependency = node.asLibraryDependency();
81 if (libraryDependency != null) { 101 if (libraryDependency != null) {
82 LibraryElement targetLibraryElement = 102 Dart2JsLibraryDependencyMirror mirror = mirrorMap[libraryDependency];
83 _element.getLibraryFromTag(libraryDependency); 103 assert(mirror != null);
84 assert(targetLibraryElement != null); 104 _libraryDependencies.add(mirror);
85 LibraryMirror targetLibrary =
86 mirrorSystem._getLibrary(targetLibraryElement);
87 _libraryDependencies.add(new Dart2JsLibraryDependencyMirror(
88 libraryDependency, this, targetLibrary));
89 } 105 }
90 } 106 }
91 } 107 }
92 } 108 }
93 109
94 List<LibraryDependencyMirror> get libraryDependencies { 110 List<LibraryDependencyMirror> get libraryDependencies {
95 _ensureLibraryDependenciesAnalyzed(); 111 _ensureLibraryDependenciesAnalyzed();
96 return _libraryDependencies; 112 return _libraryDependencies;
97 } 113 }
98 } 114 }
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 int get offset => _span.begin; 248 int get offset => _span.begin;
233 249
234 int get length => _span.end - _span.begin; 250 int get length => _span.end - _span.begin;
235 251
236 String get text => _script.text.substring(_span.begin, _span.end); 252 String get text => _script.text.substring(_span.begin, _span.end);
237 253
238 Uri get sourceUri => _script.resourceUri; 254 Uri get sourceUri => _script.resourceUri;
239 255
240 String get sourceText => _script.text; 256 String get sourceText => _script.text;
241 } 257 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/library_loader.dart ('k') | pkg/compiler/lib/src/mirrors/dart2js_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698