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

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

Issue 1859343004: dartfmt pkg/compiler (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 8 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 dart2js.mirrors; 5 library dart2js.mirrors;
6 6
7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView; 7 import 'dart:collection' show UnmodifiableListView, UnmodifiableMapView;
8 8
9 import '../common.dart'; 9 import '../common.dart';
10 import '../compiler.dart' show 10 import '../compiler.dart' show Compiler;
11 Compiler;
12 import '../constants/expressions.dart'; 11 import '../constants/expressions.dart';
13 import '../constants/values.dart'; 12 import '../constants/values.dart';
14 import '../dart_types.dart'; 13 import '../dart_types.dart';
15 import '../elements/elements.dart'; 14 import '../elements/elements.dart';
16 import '../elements/modelx.dart' show 15 import '../elements/modelx.dart' show LibraryElementX;
17 LibraryElementX; 16 import '../resolution/scope.dart' show Scope;
18 import '../resolution/scope.dart' show
19 Scope;
20 import '../script.dart'; 17 import '../script.dart';
21 import '../tokens/token.dart'; 18 import '../tokens/token.dart';
22 import '../tokens/token_constants.dart' as Tokens; 19 import '../tokens/token_constants.dart' as Tokens;
23 import '../tree/tree.dart'; 20 import '../tree/tree.dart';
24 import '../util/util.dart' 21 import '../util/util.dart' show Link, LinkBuilder;
25 show Link,
26 LinkBuilder;
27 import '../util/characters.dart' show $CR, $LF; 22 import '../util/characters.dart' show $CR, $LF;
28 23
29 import 'source_mirrors.dart'; 24 import 'source_mirrors.dart';
30 import 'mirrors_util.dart'; 25 import 'mirrors_util.dart';
31 26
32 part 'dart2js_library_mirror.dart'; 27 part 'dart2js_library_mirror.dart';
33 part 'dart2js_type_mirrors.dart'; 28 part 'dart2js_type_mirrors.dart';
34 part 'dart2js_member_mirrors.dart'; 29 part 'dart2js_member_mirrors.dart';
35 part 'dart2js_instance_mirrors.dart'; 30 part 'dart2js_instance_mirrors.dart';
36 31
37 //------------------------------------------------------------------------------ 32 //------------------------------------------------------------------------------
38 // Utility types and functions for the dart2js mirror system 33 // Utility types and functions for the dart2js mirror system
39 //------------------------------------------------------------------------------ 34 //------------------------------------------------------------------------------
40 35
41 bool _includeLibrary(Dart2JsLibraryMirror mirror) { 36 bool _includeLibrary(Dart2JsLibraryMirror mirror) {
42 return const bool.fromEnvironment("list_all_libraries") || 37 return const bool.fromEnvironment("list_all_libraries") ||
43 !mirror._element.isInternalLibrary; 38 !mirror._element.isInternalLibrary;
44 } 39 }
45 40
46 bool _isPrivate(String name) { 41 bool _isPrivate(String name) {
47 return name.startsWith('_'); 42 return name.startsWith('_');
48 } 43 }
49 44
50 List<ParameterMirror> _parametersFromFunctionSignature( 45 List<ParameterMirror> _parametersFromFunctionSignature(
51 Dart2JsDeclarationMirror owner, 46 Dart2JsDeclarationMirror owner, FunctionSignature signature) {
52 FunctionSignature signature) {
53 var parameters = <ParameterMirror>[]; 47 var parameters = <ParameterMirror>[];
54 signature.requiredParameters.forEach((FormalElement parameter) { 48 signature.requiredParameters.forEach((FormalElement parameter) {
55 parameters.add(new Dart2JsParameterMirror( 49 parameters.add(new Dart2JsParameterMirror(owner, parameter,
56 owner, parameter, isOptional: false, isNamed: false)); 50 isOptional: false, isNamed: false));
57 }); 51 });
58 bool isNamed = signature.optionalParametersAreNamed; 52 bool isNamed = signature.optionalParametersAreNamed;
59 signature.optionalParameters.forEach((FormalElement parameter) { 53 signature.optionalParameters.forEach((FormalElement parameter) {
60 parameters.add(new Dart2JsParameterMirror( 54 parameters.add(new Dart2JsParameterMirror(owner, parameter,
61 owner, parameter, isOptional: true, isNamed: isNamed)); 55 isOptional: true, isNamed: isNamed));
62 }); 56 });
63 return parameters; 57 return parameters;
64 } 58 }
65 59
66 MethodMirror _convertElementMethodToMethodMirror( 60 MethodMirror _convertElementMethodToMethodMirror(
67 Dart2JsDeclarationMirror library, Element element) { 61 Dart2JsDeclarationMirror library, Element element) {
68 if (element is FunctionElement) { 62 if (element is FunctionElement) {
69 return new Dart2JsMethodMirror(library, element); 63 return new Dart2JsMethodMirror(library, element);
70 } else { 64 } else {
71 return null; 65 return null;
72 } 66 }
73 } 67 }
74 68
75 //------------------------------------------------------------------------------ 69 //------------------------------------------------------------------------------
76 // Dart2Js specific extensions of mirror interfaces 70 // Dart2Js specific extensions of mirror interfaces
77 //------------------------------------------------------------------------------ 71 //------------------------------------------------------------------------------
78 72
79 abstract class Dart2JsMirror implements Mirror { 73 abstract class Dart2JsMirror implements Mirror {
80 Dart2JsMirrorSystem get mirrorSystem; 74 Dart2JsMirrorSystem get mirrorSystem;
81 } 75 }
82 76
83 abstract class Dart2JsDeclarationMirror extends Dart2JsMirror 77 abstract class Dart2JsDeclarationMirror extends Dart2JsMirror
84 implements DeclarationSourceMirror { 78 implements DeclarationSourceMirror {
85
86 bool get isTopLevel => owner != null && owner is LibraryMirror; 79 bool get isTopLevel => owner != null && owner is LibraryMirror;
87 80
88 bool get isPrivate => _isPrivate(_simpleNameString); 81 bool get isPrivate => _isPrivate(_simpleNameString);
89 82
90 String get _simpleNameString; 83 String get _simpleNameString;
91 84
92 String get _qualifiedNameString { 85 String get _qualifiedNameString {
93 var parent = owner; 86 var parent = owner;
94 if (parent is Dart2JsDeclarationMirror) { 87 if (parent is Dart2JsDeclarationMirror) {
95 return '${parent._qualifiedNameString}.${_simpleNameString}'; 88 return '${parent._qualifiedNameString}.${_simpleNameString}';
(...skipping 27 matching lines...) Expand all
123 var members = <Dart2JsMemberMirror>[]; 116 var members = <Dart2JsMemberMirror>[];
124 AbstractFieldElement field = element; 117 AbstractFieldElement field = element;
125 if (field.getter != null) { 118 if (field.getter != null) {
126 members.add(new Dart2JsMethodMirror(this, field.getter)); 119 members.add(new Dart2JsMethodMirror(this, field.getter));
127 } 120 }
128 if (field.setter != null) { 121 if (field.setter != null) {
129 members.add(new Dart2JsMethodMirror(this, field.setter)); 122 members.add(new Dart2JsMethodMirror(this, field.setter));
130 } 123 }
131 return members; 124 return members;
132 } 125 }
133 mirrorSystem.compiler.reporter.internalError(element, 126 mirrorSystem.compiler.reporter.internalError(
134 "Unexpected member type $element ${element.kind}."); 127 element, "Unexpected member type $element ${element.kind}.");
135 return null; 128 return null;
136 } 129 }
137 } 130 }
138 131
139 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror { 132 abstract class Dart2JsElementMirror extends Dart2JsDeclarationMirror {
140 final Dart2JsMirrorSystem mirrorSystem; 133 final Dart2JsMirrorSystem mirrorSystem;
141 final Element _element; 134 final Element _element;
142 List<InstanceMirror> _metadata; 135 List<InstanceMirror> _metadata;
143 136
144 Dart2JsElementMirror(this.mirrorSystem, this._element) { 137 Dart2JsElementMirror(this.mirrorSystem, this._element) {
145 assert (mirrorSystem != null); 138 assert(mirrorSystem != null);
146 assert (_element != null); 139 assert(_element != null);
147 } 140 }
148 141
149 String get _simpleNameString => _element.name; 142 String get _simpleNameString => _element.name;
150 143
151 /** 144 /**
152 * Computes the first token for this declaration using the begin token of the 145 * Computes the first token for this declaration using the begin token of the
153 * element node or element position as indicator. 146 * element node or element position as indicator.
154 */ 147 */
155 Token getBeginToken() { 148 Token getBeginToken() {
156 Element element = _element; 149 Element element = _element;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 Script getScript() => _element.compilationUnit.script; 189 Script getScript() => _element.compilationUnit.script;
197 190
198 SourceLocation get location { 191 SourceLocation get location {
199 Token beginToken = getFirstToken(); 192 Token beginToken = getFirstToken();
200 Script script = getScript(); 193 Script script = getScript();
201 SourceSpan span; 194 SourceSpan span;
202 if (beginToken == null) { 195 if (beginToken == null) {
203 span = new SourceSpan(script.resourceUri, 0, 0); 196 span = new SourceSpan(script.resourceUri, 0, 0);
204 } else { 197 } else {
205 Token endToken = getEndToken(); 198 Token endToken = getEndToken();
206 span = new SourceSpan.fromTokens( 199 span =
207 script.resourceUri, beginToken, endToken); 200 new SourceSpan.fromTokens(script.resourceUri, beginToken, endToken);
208 } 201 }
209 return new Dart2JsSourceLocation(script, span); 202 return new Dart2JsSourceLocation(script, span);
210 } 203 }
211 204
212 String toString() => _element.toString(); 205 String toString() => _element.toString();
213 206
214 void _appendCommentTokens(Token commentToken) { 207 void _appendCommentTokens(Token commentToken) {
215 while (commentToken != null && commentToken.kind == Tokens.COMMENT_TOKEN) { 208 while (commentToken != null && commentToken.kind == Tokens.COMMENT_TOKEN) {
216 _metadata.add(new Dart2JsCommentInstanceMirror( 209 _metadata.add(
217 mirrorSystem, commentToken.value)); 210 new Dart2JsCommentInstanceMirror(mirrorSystem, commentToken.value));
218 commentToken = commentToken.next; 211 commentToken = commentToken.next;
219 } 212 }
220 } 213 }
221 214
222 List<InstanceMirror> get metadata { 215 List<InstanceMirror> get metadata {
223 if (_metadata == null) { 216 if (_metadata == null) {
224 _metadata = <InstanceMirror>[]; 217 _metadata = <InstanceMirror>[];
225 for (MetadataAnnotation metadata in _element.metadata) { 218 for (MetadataAnnotation metadata in _element.metadata) {
226 _appendCommentTokens( 219 _appendCommentTokens(
227 mirrorSystem.compiler.commentMap[metadata.beginToken]); 220 mirrorSystem.compiler.commentMap[metadata.beginToken]);
228 metadata.ensureResolved(mirrorSystem.compiler.resolution); 221 metadata.ensureResolved(mirrorSystem.compiler.resolution);
229 _metadata.add(_convertConstantToInstanceMirror( 222 _metadata.add(_convertConstantToInstanceMirror(
230 mirrorSystem, metadata.constant, 223 mirrorSystem,
231 mirrorSystem.compiler.constants.getConstantValue( 224 metadata.constant,
232 metadata.constant))); 225 mirrorSystem.compiler.constants
226 .getConstantValue(metadata.constant)));
233 } 227 }
234 _appendCommentTokens(mirrorSystem.compiler.commentMap[getBeginToken()]); 228 _appendCommentTokens(mirrorSystem.compiler.commentMap[getBeginToken()]);
235 } 229 }
236 // TODO(johnniwinther): Return an unmodifiable list instead. 230 // TODO(johnniwinther): Return an unmodifiable list instead.
237 return new List<InstanceMirror>.from(_metadata); 231 return new List<InstanceMirror>.from(_metadata);
238 } 232 }
239 233
240 DeclarationMirror lookupInScope(String name) { 234 DeclarationMirror lookupInScope(String name) {
241 // TODO(11653): Support lookup of constructors. 235 // TODO(11653): Support lookup of constructors.
242 Scope scope = _element.buildScope(); 236 Scope scope = _element.buildScope();
243 Element result; 237 Element result;
244 int index = name.indexOf('.'); 238 int index = name.indexOf('.');
245 if (index != -1) { 239 if (index != -1) {
246 // Lookup [: prefix.id :]. 240 // Lookup [: prefix.id :].
247 String prefix = name.substring(0, index); 241 String prefix = name.substring(0, index);
248 String id = name.substring(index+1); 242 String id = name.substring(index + 1);
249 result = scope.lookup(prefix); 243 result = scope.lookup(prefix);
250 if (result != null && result.isPrefix) { 244 if (result != null && result.isPrefix) {
251 PrefixElement prefix = result; 245 PrefixElement prefix = result;
252 result = prefix.lookupLocalMember(id); 246 result = prefix.lookupLocalMember(id);
253 } else { 247 } else {
254 result = null; 248 result = null;
255 } 249 }
256 } else { 250 } else {
257 // Lookup [: id :]. 251 // Lookup [: id :].
258 result = scope.lookup(name); 252 result = scope.lookup(name);
259 } 253 }
260 if (result == null || result.isPrefix) return null; 254 if (result == null || result.isPrefix) return null;
261 return _convertElementToDeclarationMirror(mirrorSystem, result); 255 return _convertElementToDeclarationMirror(mirrorSystem, result);
262 } 256 }
263 257
264 bool operator ==(var other) { 258 bool operator ==(var other) {
265 if (identical(this, other)) return true; 259 if (identical(this, other)) return true;
266 if (other == null) return false; 260 if (other == null) return false;
267 if (other is! Dart2JsElementMirror) return false; 261 if (other is! Dart2JsElementMirror) return false;
268 return _element == other._element && 262 return _element == other._element && owner == other.owner;
269 owner == other.owner;
270 } 263 }
271 264
272 int get hashCode { 265 int get hashCode {
273 return 13 * _element.hashCode + 17 * owner.hashCode; 266 return 13 * _element.hashCode + 17 * owner.hashCode;
274 } 267 }
275 } 268 }
276 269
277 //------------------------------------------------------------------------------ 270 //------------------------------------------------------------------------------
278 // Mirror system implementation. 271 // Mirror system implementation.
279 //------------------------------------------------------------------------------ 272 //------------------------------------------------------------------------------
(...skipping 27 matching lines...) Expand all
307 Map<Uri, LibraryMirror> get libraries { 300 Map<Uri, LibraryMirror> get libraries {
308 _ensureLibraries(); 301 _ensureLibraries();
309 return _filteredLibraries; 302 return _filteredLibraries;
310 } 303 }
311 304
312 Dart2JsLibraryMirror _getLibrary(LibraryElement element) => 305 Dart2JsLibraryMirror _getLibrary(LibraryElement element) =>
313 _libraryMap[element]; 306 _libraryMap[element];
314 307
315 Dart2JsMirrorSystem get mirrorSystem => this; 308 Dart2JsMirrorSystem get mirrorSystem => this;
316 309
317 TypeMirror get dynamicType => 310 TypeMirror get dynamicType => _convertTypeToTypeMirror(const DynamicType());
318 _convertTypeToTypeMirror(const DynamicType());
319 311
320 TypeMirror get voidType => 312 TypeMirror get voidType => _convertTypeToTypeMirror(const VoidType());
321 _convertTypeToTypeMirror(const VoidType());
322 313
323 TypeMirror _convertTypeToTypeMirror(DartType type) { 314 TypeMirror _convertTypeToTypeMirror(DartType type) {
324 assert(type != null); 315 assert(type != null);
325 if (type.treatAsDynamic) { 316 if (type.treatAsDynamic) {
326 return new Dart2JsDynamicMirror(this, type); 317 return new Dart2JsDynamicMirror(this, type);
327 } else if (type is InterfaceType) { 318 } else if (type is InterfaceType) {
328 if (type.typeArguments.isEmpty) { 319 if (type.typeArguments.isEmpty) {
329 return _getTypeDeclarationMirror(type.element); 320 return _getTypeDeclarationMirror(type.element);
330 } else { 321 } else {
331 return new Dart2JsInterfaceTypeMirror(this, type); 322 return new Dart2JsInterfaceTypeMirror(this, type);
332 } 323 }
333 } else if (type is TypeVariableType) { 324 } else if (type is TypeVariableType) {
334 return new Dart2JsTypeVariableMirror(this, type); 325 return new Dart2JsTypeVariableMirror(this, type);
335 } else if (type is FunctionType) { 326 } else if (type is FunctionType) {
336 return new Dart2JsFunctionTypeMirror(this, type); 327 return new Dart2JsFunctionTypeMirror(this, type);
337 } else if (type is VoidType) { 328 } else if (type is VoidType) {
338 return new Dart2JsVoidMirror(this, type); 329 return new Dart2JsVoidMirror(this, type);
339 } else if (type is TypedefType) { 330 } else if (type is TypedefType) {
340 if (type.typeArguments.isEmpty) { 331 if (type.typeArguments.isEmpty) {
341 return _getTypeDeclarationMirror(type.element); 332 return _getTypeDeclarationMirror(type.element);
342 } else { 333 } else {
343 return new Dart2JsTypedefMirror(this, type); 334 return new Dart2JsTypedefMirror(this, type);
344 } 335 }
345 } 336 }
346 compiler.reporter.internalError(type.element, 337 compiler.reporter.internalError(
347 "Unexpected type $type of kind ${type.kind}."); 338 type.element, "Unexpected type $type of kind ${type.kind}.");
348 return null; 339 return null;
349 } 340 }
350 341
351 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) { 342 DeclarationMirror _getTypeDeclarationMirror(TypeDeclarationElement element) {
352 if (element.isClass) { 343 if (element.isClass) {
353 return new Dart2JsClassDeclarationMirror(this, element.thisType); 344 return new Dart2JsClassDeclarationMirror(this, element.thisType);
354 } else if (element.isTypedef) { 345 } else if (element.isTypedef) {
355 return new Dart2JsTypedefDeclarationMirror(this, element.thisType); 346 return new Dart2JsTypedefDeclarationMirror(this, element.thisType);
356 } 347 }
357 compiler.reporter.internalError(element, "Unexpected element $element."); 348 compiler.reporter.internalError(element, "Unexpected element $element.");
358 return null; 349 return null;
359 } 350 }
360 } 351 }
361 352
362 abstract class ContainerMixin { 353 abstract class ContainerMixin {
363 UnmodifiableMapView<Symbol, DeclarationMirror> _declarations; 354 UnmodifiableMapView<Symbol, DeclarationMirror> _declarations;
364 355
365 void _ensureDeclarations() { 356 void _ensureDeclarations() {
366 if (_declarations == null) { 357 if (_declarations == null) {
367 var declarations = <Symbol, DeclarationMirror>{}; 358 var declarations = <Symbol, DeclarationMirror>{};
368 _forEachElement((Element element) { 359 _forEachElement((Element element) {
369 for (DeclarationMirror mirror in _getDeclarationMirrors(element)) { 360 for (DeclarationMirror mirror in _getDeclarationMirrors(element)) {
370 assert(invariant(_element, 361 assert(
371 !declarations.containsKey(mirror.simpleName), 362 invariant(_element, !declarations.containsKey(mirror.simpleName),
372 message: "Declaration name '${nameOf(mirror)}' " 363 message: "Declaration name '${nameOf(mirror)}' "
373 "is not unique in $_element.")); 364 "is not unique in $_element."));
374 declarations[mirror.simpleName] = mirror; 365 declarations[mirror.simpleName] = mirror;
375 } 366 }
376 }); 367 });
377 _declarations = 368 _declarations =
378 new UnmodifiableMapView<Symbol, DeclarationMirror>(declarations); 369 new UnmodifiableMapView<Symbol, DeclarationMirror>(declarations);
379 } 370 }
380 } 371 }
381 372
382 Element get _element; 373 Element get _element;
383 374
384 void _forEachElement(f(Element element)); 375 void _forEachElement(f(Element element));
385 376
386 Iterable<Dart2JsMemberMirror> _getDeclarationMirrors(Element element); 377 Iterable<Dart2JsMemberMirror> _getDeclarationMirrors(Element element);
387 378
388 Map<Symbol, DeclarationMirror> get declarations { 379 Map<Symbol, DeclarationMirror> get declarations {
389 _ensureDeclarations(); 380 _ensureDeclarations();
390 return _declarations; 381 return _declarations;
391 } 382 }
392 } 383 }
393 384
394 /** 385 /**
395 * Converts [element] into its corresponding [DeclarationMirror], if any. 386 * Converts [element] into its corresponding [DeclarationMirror], if any.
396 * 387 *
397 * If [element] is an [AbstractFieldElement] the mirror for its getter is 388 * If [element] is an [AbstractFieldElement] the mirror for its getter is
398 * returned or, if not present, the mirror for its setter. 389 * returned or, if not present, the mirror for its setter.
399 */ 390 */
400 DeclarationMirror _convertElementToDeclarationMirror(Dart2JsMirrorSystem system, 391 DeclarationMirror _convertElementToDeclarationMirror(
401 Element element) { 392 Dart2JsMirrorSystem system, Element element) {
402 if (element.isTypeVariable) { 393 if (element.isTypeVariable) {
403 TypeVariableElement typeVariable = element; 394 TypeVariableElement typeVariable = element;
404 return new Dart2JsTypeVariableMirror(system, typeVariable.type); 395 return new Dart2JsTypeVariableMirror(system, typeVariable.type);
405 } 396 }
406 397
407 Dart2JsLibraryMirror library = system._libraryMap[element.library]; 398 Dart2JsLibraryMirror library = system._libraryMap[element.library];
408 if (element.isLibrary) return library; 399 if (element.isLibrary) return library;
409 if (element.isTypedef) { 400 if (element.isTypedef) {
410 TypedefElement typedefElement = element; 401 TypedefElement typedefElement = element;
411 return new Dart2JsTypedefMirror.fromLibrary( 402 return new Dart2JsTypedefMirror.fromLibrary(
412 library, typedefElement.thisType); 403 library, typedefElement.thisType);
413 } 404 }
414 405
415 Dart2JsDeclarationMirror container = library; 406 Dart2JsDeclarationMirror container = library;
416 if (element.enclosingClass != null) { 407 if (element.enclosingClass != null) {
417 container = system._getTypeDeclarationMirror(element.enclosingClass); 408 container = system._getTypeDeclarationMirror(element.enclosingClass);
418 } 409 }
419 if (element.isClass) return container; 410 if (element.isClass) return container;
420 if (element.isParameter) { 411 if (element.isParameter) {
421 Dart2JsMethodMirror method = _convertElementMethodToMethodMirror( 412 Dart2JsMethodMirror method = _convertElementMethodToMethodMirror(
422 container, element.outermostEnclosingMemberOrTopLevel); 413 container, element.outermostEnclosingMemberOrTopLevel);
423 // TODO(johnniwinther): Find the right info for [isOptional] and [isNamed]. 414 // TODO(johnniwinther): Find the right info for [isOptional] and [isNamed].
424 return new Dart2JsParameterMirror( 415 return new Dart2JsParameterMirror(method, element,
425 method, element, isOptional: false, isNamed: false); 416 isOptional: false, isNamed: false);
426 } 417 }
427 Iterable<DeclarationMirror> members = 418 Iterable<DeclarationMirror> members =
428 container._getDeclarationMirrors(element); 419 container._getDeclarationMirrors(element);
429 if (members.isEmpty) return null; 420 if (members.isEmpty) return null;
430 return members.first; 421 return members.first;
431 } 422 }
432 423
433 /** 424 /**
434 * Experimental API for accessing compilation units defined in a 425 * Experimental API for accessing compilation units defined in a
435 * library. 426 * library.
(...skipping 19 matching lines...) Expand all
455 446
456 /** 447 /**
457 * Transitional class that allows access to features that have not yet 448 * Transitional class that allows access to features that have not yet
458 * made it to the mirror API. 449 * made it to the mirror API.
459 * 450 *
460 * All API in this class is experimental. 451 * All API in this class is experimental.
461 */ 452 */
462 class BackDoor { 453 class BackDoor {
463 /// Return the compilation units comprising [library]. 454 /// Return the compilation units comprising [library].
464 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) { 455 static List<Mirror> compilationUnitsOf(Dart2JsLibraryMirror library) {
465 return library._element.compilationUnits.mapToList( 456 return library._element.compilationUnits
466 (cu) => new Dart2JsCompilationUnitMirror(cu, library)); 457 .mapToList((cu) => new Dart2JsCompilationUnitMirror(cu, library));
467 } 458 }
468 459
469 static Iterable<ConstantExpression> metadataSyntaxOf( 460 static Iterable<ConstantExpression> metadataSyntaxOf(
470 Dart2JsElementMirror declaration) { 461 Dart2JsElementMirror declaration) {
471 return declaration._element.metadata.map((metadata) => metadata.constant); 462 return declaration._element.metadata.map((metadata) => metadata.constant);
472 } 463 }
473 464
474 static ConstantExpression initializerSyntaxOf(Dart2JsFieldMirror variable) { 465 static ConstantExpression initializerSyntaxOf(Dart2JsFieldMirror variable) {
475 Compiler compiler = variable.mirrorSystem.compiler; 466 Compiler compiler = variable.mirrorSystem.compiler;
476 return compiler.constants.getConstantForVariable(variable._variable); 467 return compiler.constants.getConstantForVariable(variable._variable);
477 } 468 }
478 469
479 static ConstantExpression defaultValueSyntaxOf( 470 static ConstantExpression defaultValueSyntaxOf(
480 Dart2JsParameterMirror parameter) { 471 Dart2JsParameterMirror parameter) {
481 if (!parameter.hasDefaultValue) return null; 472 if (!parameter.hasDefaultValue) return null;
482 ParameterElement parameterElement = parameter._element; 473 ParameterElement parameterElement = parameter._element;
483 Compiler compiler = parameter.mirrorSystem.compiler; 474 Compiler compiler = parameter.mirrorSystem.compiler;
484 return compiler.constants.getConstantForVariable(parameterElement); 475 return compiler.constants.getConstantForVariable(parameterElement);
485 } 476 }
486 477
487 static Mirror getMirrorFromElement(Dart2JsMirror mirror, Element element) { 478 static Mirror getMirrorFromElement(Dart2JsMirror mirror, Element element) {
488 return _convertElementToDeclarationMirror(mirror.mirrorSystem, element); 479 return _convertElementToDeclarationMirror(mirror.mirrorSystem, element);
489 } 480 }
490 } 481 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/mirrors/dart2js_member_mirrors.dart ('k') | pkg/compiler/lib/src/mirrors/dart2js_type_mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698