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 part of dart2js.mirrors; | 5 part of dart2js.mirrors; |
6 | 6 |
7 class Dart2JsLibraryMirror | 7 class Dart2JsLibraryMirror extends Dart2JsElementMirror |
8 extends Dart2JsElementMirror | |
9 with ObjectMirrorMixin, ContainerMixin | 8 with ObjectMirrorMixin, ContainerMixin |
10 implements LibrarySourceMirror { | 9 implements LibrarySourceMirror { |
11 List<LibraryDependencySourceMirror> _libraryDependencies; | 10 List<LibraryDependencySourceMirror> _libraryDependencies; |
12 | 11 |
13 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) | 12 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) |
14 : super(system, library); | 13 : super(system, library); |
15 | 14 |
16 Function operator [](Symbol name) { | 15 Function operator [](Symbol name) { |
17 throw new UnsupportedError('LibraryMirror.operator [] unsupported.'); | 16 throw new UnsupportedError('LibraryMirror.operator [] unsupported.'); |
18 } | 17 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 return null; | 72 return null; |
74 } | 73 } |
75 | 74 |
76 void _ensureLibraryDependenciesAnalyzed() { | 75 void _ensureLibraryDependenciesAnalyzed() { |
77 if (_libraryDependencies == null) { | 76 if (_libraryDependencies == null) { |
78 // TODO(johnniwinther): Support order of declarations on [LibraryElement]. | 77 // TODO(johnniwinther): Support order of declarations on [LibraryElement]. |
79 Map<LibraryDependency, Dart2JsLibraryDependencyMirror> mirrorMap = | 78 Map<LibraryDependency, Dart2JsLibraryDependencyMirror> mirrorMap = |
80 <LibraryDependency, Dart2JsLibraryDependencyMirror>{}; | 79 <LibraryDependency, Dart2JsLibraryDependencyMirror>{}; |
81 | 80 |
82 void addLibraryDependency(LibraryDependency libraryDependency, | 81 void addLibraryDependency(LibraryDependency libraryDependency, |
83 LibraryElement targetLibraryElement) { | 82 LibraryElement targetLibraryElement) { |
84 assert(targetLibraryElement != null); | 83 assert(targetLibraryElement != null); |
85 LibraryMirror targetLibrary = | 84 LibraryMirror targetLibrary = |
86 mirrorSystem._getLibrary(targetLibraryElement); | 85 mirrorSystem._getLibrary(targetLibraryElement); |
87 mirrorMap[libraryDependency] = new Dart2JsLibraryDependencyMirror( | 86 mirrorMap[libraryDependency] = new Dart2JsLibraryDependencyMirror( |
88 libraryDependency, this, targetLibrary); | 87 libraryDependency, this, targetLibrary); |
89 } | 88 } |
90 for (ImportElement import in _element.imports) { | 89 for (ImportElement import in _element.imports) { |
91 addLibraryDependency(import.node, import.importedLibrary); | 90 addLibraryDependency(import.node, import.importedLibrary); |
92 } | 91 } |
93 for (ExportElement export in _element.exports) { | 92 for (ExportElement export in _element.exports) { |
(...skipping 18 matching lines...) Expand all Loading... |
112 return _libraryDependencies; | 111 return _libraryDependencies; |
113 } | 112 } |
114 } | 113 } |
115 | 114 |
116 class Dart2JsLibraryDependencyMirror implements LibraryDependencySourceMirror { | 115 class Dart2JsLibraryDependencyMirror implements LibraryDependencySourceMirror { |
117 final LibraryDependency _node; | 116 final LibraryDependency _node; |
118 final Dart2JsLibraryMirror _sourceLibrary; | 117 final Dart2JsLibraryMirror _sourceLibrary; |
119 final Dart2JsLibraryMirror _targetLibrary; | 118 final Dart2JsLibraryMirror _targetLibrary; |
120 List<CombinatorMirror> _combinators; | 119 List<CombinatorMirror> _combinators; |
121 | 120 |
122 Dart2JsLibraryDependencyMirror(this._node, | 121 Dart2JsLibraryDependencyMirror( |
123 this._sourceLibrary, | 122 this._node, this._sourceLibrary, this._targetLibrary); |
124 this._targetLibrary); | |
125 | 123 |
126 SourceLocation get location { | 124 SourceLocation get location { |
127 return new Dart2JsSourceLocation( | 125 return new Dart2JsSourceLocation( |
128 _sourceLibrary._element.entryCompilationUnit.script, | 126 _sourceLibrary._element.entryCompilationUnit.script, |
129 _sourceLibrary.mirrorSystem.compiler.reporter.spanFromSpannable(_node)); | 127 _sourceLibrary.mirrorSystem.compiler.reporter.spanFromSpannable(_node)); |
130 } | 128 } |
131 | 129 |
132 List<CombinatorMirror> get combinators { | 130 List<CombinatorMirror> get combinators { |
133 if (_combinators == null) { | 131 if (_combinators == null) { |
134 _combinators = <CombinatorMirror>[]; | 132 _combinators = <CombinatorMirror>[]; |
135 if (_node.combinators != null) { | 133 if (_node.combinators != null) { |
136 for (Combinator combinator in _node.combinators.nodes) { | 134 for (Combinator combinator in _node.combinators.nodes) { |
137 List<String> identifiers = <String>[]; | 135 List<String> identifiers = <String>[]; |
138 for (Identifier identifier in combinator.identifiers.nodes) { | 136 for (Identifier identifier in combinator.identifiers.nodes) { |
139 identifiers.add(identifier.source); | 137 identifiers.add(identifier.source); |
140 } | 138 } |
141 _combinators.add(new Dart2JsCombinatorMirror( | 139 _combinators.add(new Dart2JsCombinatorMirror(identifiers, |
142 identifiers, isShow: combinator.isShow)); | 140 isShow: combinator.isShow)); |
143 } | 141 } |
144 } | 142 } |
145 } | 143 } |
146 return _combinators; | 144 return _combinators; |
147 } | 145 } |
148 | 146 |
149 LibraryMirror get sourceLibrary => _sourceLibrary; | 147 LibraryMirror get sourceLibrary => _sourceLibrary; |
150 | 148 |
151 LibraryMirror get targetLibrary => _targetLibrary; | 149 LibraryMirror get targetLibrary => _targetLibrary; |
152 | 150 |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
248 int get offset => _span.begin; | 246 int get offset => _span.begin; |
249 | 247 |
250 int get length => _span.end - _span.begin; | 248 int get length => _span.end - _span.begin; |
251 | 249 |
252 String get text => _script.text.substring(_span.begin, _span.end); | 250 String get text => _script.text.substring(_span.begin, _span.end); |
253 | 251 |
254 Uri get sourceUri => _script.resourceUri; | 252 Uri get sourceUri => _script.resourceUri; |
255 | 253 |
256 String get sourceText => _script.text; | 254 String get sourceText => _script.text; |
257 } | 255 } |
OLD | NEW |