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

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

Issue 693183006: Revert "Move dart2js from sdk/lib/_internal/compiler to pkg/compiler" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 part of dart2js.mirrors;
6
7
8 class Dart2JsLibraryMirror
9 extends Dart2JsElementMirror
10 with ObjectMirrorMixin, ContainerMixin
11 implements LibrarySourceMirror {
12 List<LibraryDependencySourceMirror> _libraryDependencies;
13
14 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library)
15 : super(system, library);
16
17 Function operator [](Symbol name) {
18 throw new UnsupportedError('LibraryMirror.operator [] unsupported.');
19 }
20
21 LibraryElement get _element => super._element;
22
23 Uri get uri => _element.canonicalUri;
24
25 DeclarationMirror get owner => null;
26
27 bool get isPrivate => false;
28
29 LibraryMirror library() => this;
30
31 /**
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
34 * provide a 'library name' for scripts, to use for instance in dartdoc.
35 */
36 String get _simpleNameString {
37 if (_element.libraryTag != null) {
38 return _element.libraryTag.name.toString();
39 } else {
40 // Use the file name as script name.
41 String path = _element.canonicalUri.path;
42 return path.substring(path.lastIndexOf('/') + 1);
43 }
44 }
45
46 Symbol get qualifiedName => simpleName;
47
48 void _forEachElement(f(Element element)) => _element.forEachLocalMember(f);
49
50 Iterable<Dart2JsDeclarationMirror> _getDeclarationMirrors(Element element) {
51 if (element.isClass || element.isTypedef) {
52 return [mirrorSystem._getTypeDeclarationMirror(element)];
53 } else {
54 return super._getDeclarationMirrors(element);
55 }
56 }
57
58 Map<Symbol, MethodMirror> get topLevelMembers => null;
59
60 /**
61 * Computes the first token of this library using the first library tag as
62 * indicator.
63 */
64 Token getBeginToken() {
65 if (_element.libraryTag != null) {
66 return _element.libraryTag.getBeginToken();
67 } else if (!_element.tags.isEmpty) {
68 return _element.tags.first.getBeginToken();
69 }
70 return null;
71 }
72
73 /**
74 * Computes the first token of this library using the last library tag as
75 * indicator.
76 */
77 Token getEndToken() {
78 if (!_element.tags.isEmpty) {
79 return _element.tags.last.getEndToken();
80 }
81 return null;
82 }
83
84 void _ensureLibraryDependenciesAnalyzed() {
85 if (_libraryDependencies == null) {
86 _libraryDependencies = <LibraryDependencySourceMirror>[];
87 for (LibraryTag node in _element.tags) {
88 LibraryDependency libraryDependency = node.asLibraryDependency();
89 if (libraryDependency != null) {
90 LibraryElement targetLibraryElement =
91 _element.getLibraryFromTag(libraryDependency);
92 assert(targetLibraryElement != null);
93 LibraryMirror targetLibrary =
94 mirrorSystem._getLibrary(targetLibraryElement);
95 _libraryDependencies.add(new Dart2JsLibraryDependencyMirror(
96 libraryDependency, this, targetLibrary));
97 }
98 }
99 }
100 }
101
102 List<LibraryDependencyMirror> get libraryDependencies {
103 _ensureLibraryDependenciesAnalyzed();
104 return _libraryDependencies;
105 }
106 }
107
108 class Dart2JsLibraryDependencyMirror implements LibraryDependencySourceMirror {
109 final LibraryDependency _node;
110 final Dart2JsLibraryMirror _sourceLibrary;
111 final Dart2JsLibraryMirror _targetLibrary;
112 List<CombinatorMirror> _combinators;
113
114 Dart2JsLibraryDependencyMirror(this._node,
115 this._sourceLibrary,
116 this._targetLibrary);
117
118 SourceLocation get location {
119 return new Dart2JsSourceLocation(
120 _sourceLibrary._element.entryCompilationUnit.script,
121 _sourceLibrary.mirrorSystem.compiler.spanFromNode(_node));
122 }
123
124 List<CombinatorMirror> get combinators {
125 if (_combinators == null) {
126 _combinators = <CombinatorMirror>[];
127 if (_node.combinators != null) {
128 for (Combinator combinator in _node.combinators.nodes) {
129 List<String> identifiers = <String>[];
130 for (Identifier identifier in combinator.identifiers.nodes) {
131 identifiers.add(identifier.source);
132 }
133 _combinators.add(new Dart2JsCombinatorMirror(
134 identifiers, isShow: combinator.isShow));
135 }
136 }
137 }
138 return _combinators;
139 }
140
141 LibraryMirror get sourceLibrary => _sourceLibrary;
142
143 LibraryMirror get targetLibrary => _targetLibrary;
144
145 /*String*/ get prefix {
146 Import import = _node.asImport();
147 if (import != null && import.prefix != null) {
148 return import.prefix.source;
149 }
150 return null;
151 }
152
153 bool get isImport => _node.asImport() != null;
154
155 bool get isExport => _node.asExport() != null;
156
157 List<InstanceMirror> get metadata => const <InstanceMirror>[];
158 }
159
160 class Dart2JsCombinatorMirror implements CombinatorSourceMirror {
161 final List/*<String>*/ identifiers;
162 final bool isShow;
163
164 Dart2JsCombinatorMirror(this.identifiers, {bool isShow: true})
165 : this.isShow = isShow;
166
167 bool get isHide => !isShow;
168 }
169
170 class Dart2JsSourceLocation implements SourceLocation {
171 final Script _script;
172 final SourceSpan _span;
173 int _line;
174 int _column;
175
176 Dart2JsSourceLocation(this._script, this._span);
177
178 int _computeLine() {
179 var sourceFile = _script.file;
180 if (sourceFile != null) {
181 return sourceFile.getLine(offset) + 1;
182 }
183 var index = 0;
184 var lineNumber = 0;
185 while (index <= offset && index < sourceText.length) {
186 index = sourceText.indexOf('\n', index) + 1;
187 if (index <= 0) break;
188 lineNumber++;
189 }
190 return lineNumber;
191 }
192
193 int get line {
194 if (_line == null) {
195 _line = _computeLine();
196 }
197 return _line;
198 }
199
200 int _computeColumn() {
201 if (length == 0) return 0;
202
203 var sourceFile = _script.file;
204 if (sourceFile != null) {
205 return sourceFile.getColumn(sourceFile.getLine(offset), offset) + 1;
206 }
207 int index = offset - 1;
208 var columnNumber = 0;
209 while (0 <= index && index < sourceText.length) {
210 columnNumber++;
211 var codeUnit = sourceText.codeUnitAt(index);
212 if (codeUnit == $CR || codeUnit == $LF) {
213 break;
214 }
215 index--;
216 }
217 return columnNumber;
218 }
219
220 int get column {
221 if (_column == null) {
222 _column = _computeColumn();
223 }
224 return _column;
225 }
226
227 int get offset => _span.begin;
228
229 int get length => _span.end - _span.begin;
230
231 String get text => _script.text.substring(_span.begin, _span.end);
232
233 Uri get sourceUri => _script.resourceUri;
234
235 String get sourceText => _script.text;
236 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/mirrors/dart2js_instance_mirrors.dart ('k') | pkg/compiler/lib/src/mirrors/dart2js_member_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698