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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mirror.dart

Issue 14775002: Add LibraryDependencyMirror+CombinatorMirror to source mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 mirrors_dart2js; 5 library mirrors_dart2js;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection' show LinkedHashMap; 8 import 'dart:collection' show LinkedHashMap;
9 import 'dart:uri'; 9 import 'dart:uri';
10 10
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 _ensureMembers(); 476 _ensureMembers();
477 return new AsFilteredImmutableMap<String, MemberMirror, VariableMirror>( 477 return new AsFilteredImmutableMap<String, MemberMirror, VariableMirror>(
478 _members, 478 _members,
479 (MemberMirror member) => member is VariableMirror ? member : null); 479 (MemberMirror member) => member is VariableMirror ? member : null);
480 } 480 }
481 } 481 }
482 482
483 class Dart2JsLibraryMirror extends Dart2JsContainerMirror 483 class Dart2JsLibraryMirror extends Dart2JsContainerMirror
484 implements LibraryMirror { 484 implements LibraryMirror {
485 Map<String, ClassMirror> _classes; 485 Map<String, ClassMirror> _classes;
486 List<LibraryDependencyMirror> _libraryDependencies;
487
486 488
487 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) 489 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library)
488 : super(system, library); 490 : super(system, library);
489 491
490 LibraryElement get _library => _element; 492 LibraryElement get _library => _element;
491 493
492 Uri get uri => _library.canonicalUri; 494 Uri get uri => _library.canonicalUri;
493 495
494 DeclarationMirror get owner => null; 496 DeclarationMirror get owner => null;
495 497
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 /** 581 /**
580 * Computes the first token of this library using the last library tag as 582 * Computes the first token of this library using the last library tag as
581 * indicator. 583 * indicator.
582 */ 584 */
583 Token getEndToken() { 585 Token getEndToken() {
584 if (!_library.tags.isEmpty) { 586 if (!_library.tags.isEmpty) {
585 return _library.tags.head.getEndToken(); 587 return _library.tags.head.getEndToken();
586 } 588 }
587 return null; 589 return null;
588 } 590 }
591
592 void _ensureLibraryDependencies() {
593 if (_libraryDependencies == null) {
594 _libraryDependencies = new List<LibraryDependencyMirror>();
595 for (LibraryTag node in _library.tags) {
596 LibraryDependency libraryDependency = node.asLibraryDependency();
597 if (libraryDependency != null) {
598 LibraryElement targetLibraryElement =
599 _library.getLibraryFromTag(libraryDependency);
600 assert(targetLibraryElement != null);
601 LibraryMirror targetLibrary =
602 mirrors._getLibrary(targetLibraryElement);
603 _libraryDependencies.add(new Dart2JsLibraryDependencyMirror(
604 libraryDependency, this, targetLibrary));
605 }
606 }
607 }
608 }
609
610 List<LibraryDependencyMirror> get libraryDependencies {
611 _ensureLibraryDependencies();
612 return _libraryDependencies;
613 }
614 }
615
616 class Dart2JsLibraryDependencyMirror implements LibraryDependencyMirror {
617 final LibraryDependency _node;
618 final Dart2JsLibraryMirror _sourceLibrary;
619 final Dart2JsLibraryMirror _targetLibrary;
620 List<CombinatorMirror> _combinators;
621
622 Dart2JsLibraryDependencyMirror(this._node,
623 this._sourceLibrary,
624 this._targetLibrary);
625
626 SourceLocation get location {
627 return new Dart2JsSourceLocation(
628 _sourceLibrary._library.entryCompilationUnit.script,
629 _sourceLibrary.mirrors.compiler.spanFromNode(_node));
630 }
631
632 List<CombinatorMirror> get combinators {
633 if (_combinators == null) {
634 _combinators = <CombinatorMirror>[];
635 if (_node.combinators != null) {
636 for (Combinator combinator in _node.combinators.nodes) {
637 List<String> identifiers = <String>[];
638 for (Identifier identifier in combinator.identifiers.nodes) {
639 identifiers.add(identifier.source.slowToString());
640 }
641 _combinators.add(new Dart2JsCombinatorMirror(
642 identifiers, isShow: combinator.isShow));
643 }
644 }
645 }
646 return _combinators;
647 }
648
649 LibraryMirror get sourceLibrary => _sourceLibrary;
650
651 LibraryMirror get targetLibrary => _targetLibrary;
652
653 String get prefix {
654 Import import = _node.asImport();
655 if (import != null && import.prefix != null) {
656 return import.prefix.source.slowToString();
657 }
658 return null;
659 }
660
661 bool get isImport => _node.asImport() != null;
662
663 bool get isExport => _node.asExport() != null;
664 }
665
666 class Dart2JsCombinatorMirror implements CombinatorMirror {
667 final List<String> identifiers;
668 final bool isShow;
669
670 Dart2JsCombinatorMirror(this.identifiers, {bool isShow: true})
671 : this.isShow = isShow;
672
673 bool get isHide => !isShow;
589 } 674 }
590 675
591 class Dart2JsSourceLocation implements SourceLocation { 676 class Dart2JsSourceLocation implements SourceLocation {
592 final Script _script; 677 final Script _script;
593 final SourceSpan _span; 678 final SourceSpan _span;
594 int _line; 679 int _line;
595 int _column; 680 int _column;
596 681
597 Dart2JsSourceLocation(this._script, this._span); 682 Dart2JsSourceLocation(this._script, this._span);
598 683
(...skipping 1076 matching lines...) Expand 10 before | Expand all | Expand 10 after
1675 return new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment); 1760 return new Dart2JsBoolConstantMirror.fromBool(mirrors, isDocComment);
1676 } else if (fieldName == 'text') { 1761 } else if (fieldName == 'text') {
1677 return new Dart2JsStringConstantMirror.fromString(mirrors, text); 1762 return new Dart2JsStringConstantMirror.fromString(mirrors, text);
1678 } else if (fieldName == 'trimmedText') { 1763 } else if (fieldName == 'trimmedText') {
1679 return new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText); 1764 return new Dart2JsStringConstantMirror.fromString(mirrors, trimmedText);
1680 } 1765 }
1681 // TODO(johnniwinther): Which exception/error should be thrown here? 1766 // TODO(johnniwinther): Which exception/error should be thrown here?
1682 throw new UnsupportedError('InstanceMirror does not have a reflectee'); 1767 throw new UnsupportedError('InstanceMirror does not have a reflectee');
1683 } 1768 }
1684 } 1769 }
OLDNEW
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/mirrors/mirrors.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698