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

Side by Side Diff: pkg/dartdoc/lib/src/mirrors/dart2js_mirror.dart

Issue 11342039: LibraryMirror interface updated to match dart:mirrors. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comment Created 8 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
« no previous file with comments | « pkg/dartdoc/lib/mirrors_util.dart ('k') | tests/compiler/dart2js/mirrors_test.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:io'; 7 import 'dart:io';
8 import 'dart:uri'; 8 import 'dart:uri';
9 9
10 import '../../../../../lib/compiler/compiler.dart' as diagnostics; 10 import '../../../../../lib/compiler/compiler.dart' as diagnostics;
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 } 477 }
478 478
479 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror 479 abstract class Dart2JsObjectMirror extends Dart2JsElementMirror
480 implements ObjectMirror { 480 implements ObjectMirror {
481 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element) 481 Dart2JsObjectMirror(Dart2JsMirrorSystem system, Element element)
482 : super(system, element); 482 : super(system, element);
483 } 483 }
484 484
485 class Dart2JsLibraryMirror extends Dart2JsObjectMirror 485 class Dart2JsLibraryMirror extends Dart2JsObjectMirror
486 implements LibraryMirror { 486 implements LibraryMirror {
487 Map<String, ClassMirror> _types; 487 Map<String, ClassMirror> _classes;
488 Map<String, MemberMirror> _members; 488 Map<String, MemberMirror> _members;
489 489
490 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library) 490 Dart2JsLibraryMirror(Dart2JsMirrorSystem system, LibraryElement library)
491 : super(system, library); 491 : super(system, library);
492 492
493 LibraryElement get _library => _element; 493 LibraryElement get _library => _element;
494 494
495 Uri get uri => _library.uri; 495 Uri get uri => _library.uri;
496 496
497 DeclarationMirror get owner => null; 497 DeclarationMirror get owner => null;
(...skipping 18 matching lines...) Expand all
516 } 516 }
517 } else { 517 } else {
518 // Use the file name as script name. 518 // Use the file name as script name.
519 String path = _library.uri.path; 519 String path = _library.uri.path;
520 return path.substring(path.lastIndexOf('/') + 1); 520 return path.substring(path.lastIndexOf('/') + 1);
521 } 521 }
522 } 522 }
523 523
524 String get qualifiedName => simpleName; 524 String get qualifiedName => simpleName;
525 525
526 void _ensureTypes() { 526 void _ensureClasses() {
527 if (_types == null) { 527 if (_classes == null) {
528 _types = <String, ClassMirror>{}; 528 _classes = <String, ClassMirror>{};
529 _library.forEachLocalMember((Element e) { 529 _library.forEachLocalMember((Element e) {
530 if (e.isClass()) { 530 if (e.isClass()) {
531 e.ensureResolved(system.compiler); 531 e.ensureResolved(system.compiler);
532 var type = new Dart2JsClassMirror.fromLibrary(this, e); 532 var type = new Dart2JsClassMirror.fromLibrary(this, e);
533 assert(invariant(_library, !_types.containsKey(type.simpleName), 533 assert(invariant(_library, !_classes.containsKey(type.simpleName),
534 message: "Type name '${type.simpleName}' " 534 message: "Type name '${type.simpleName}' "
535 "is not unique in $_library.")); 535 "is not unique in $_library."));
536 _types[type.simpleName] = type; 536 _classes[type.simpleName] = type;
537 } else if (e.isTypedef()) { 537 } else if (e.isTypedef()) {
538 var type = new Dart2JsTypedefMirror.fromLibrary(this, 538 var type = new Dart2JsTypedefMirror.fromLibrary(this,
539 e.computeType(system.compiler)); 539 e.computeType(system.compiler));
540 assert(invariant(_library, !_types.containsKey(type.simpleName), 540 assert(invariant(_library, !_classes.containsKey(type.simpleName),
541 message: "Type name '${type.simpleName}' " 541 message: "Type name '${type.simpleName}' "
542 "is not unique in $_library.")); 542 "is not unique in $_library."));
543 _types[type.simpleName] = type; 543 _classes[type.simpleName] = type;
544 } 544 }
545 }); 545 });
546 } 546 }
547 } 547 }
548 548
549 void _ensureMembers() { 549 void _ensureMembers() {
550 if (_members == null) { 550 if (_members == null) {
551 _members = <String, MemberMirror>{}; 551 _members = <String, MemberMirror>{};
552 _library.forEachLocalMember((Element e) { 552 _library.forEachLocalMember((Element e) {
553 if (!e.isClass() && !e.isTypedef()) { 553 if (!e.isClass() && !e.isTypedef()) {
554 for (var member in _convertElementMemberToMemberMirrors(this, e)) { 554 for (var member in _convertElementMemberToMemberMirrors(this, e)) {
555 assert(!_members.containsKey(member.simpleName)); 555 assert(!_members.containsKey(member.simpleName));
556 _members[member.simpleName] = member; 556 _members[member.simpleName] = member;
557 } 557 }
558 } 558 }
559 }); 559 });
560 } 560 }
561 } 561 }
562 562
563 Map<String, MemberMirror> get declaredMembers { 563 Map<String, MemberMirror> get declaredMembers {
564 _ensureMembers(); 564 _ensureMembers();
565 return new ImmutableMapWrapper<String, MemberMirror>(_members); 565 return new ImmutableMapWrapper<String, MemberMirror>(_members);
566 } 566 }
567 567
568 Map<String, ClassMirror> get types { 568 Map<String, Mirror> get members => declaredMembers;
569 _ensureTypes(); 569
570 return new ImmutableMapWrapper<String, ClassMirror>(_types); 570 Map<String, MethodMirror> get functions {
571 _ensureMembers();
572 return new FilteredImmutableMap(_members,
573 (MemberMirror member) => member is MethodMirror);
574 }
575
576 Map<String, MethodMirror> get getters {
577 _ensureMembers();
578 return new FilteredImmutableMap(_members,
579 (MemberMirror member) => member is MethodMirror && member.isGetter);
580 }
581
582 Map<String, MethodMirror> get setters {
583 _ensureMembers();
584 return new FilteredImmutableMap(_members,
585 (MemberMirror member) => member is MethodMirror && member.isSetter);
586 }
587
588 Map<String, ClassMirror> get classes {
589 _ensureClasses();
590 return new ImmutableMapWrapper<String, ClassMirror>(_classes);
571 } 591 }
572 592
573 SourceLocation get location { 593 SourceLocation get location {
574 var script = _library.getCompilationUnit().script; 594 var script = _library.getCompilationUnit().script;
575 return new Dart2JsLocation( 595 return new Dart2JsLocation(
576 script, 596 script,
577 new SourceSpan(script.uri, 0, script.text.length)); 597 new SourceSpan(script.uri, 0, script.text.length));
578 } 598 }
579 } 599 }
580 600
(...skipping 824 matching lines...) Expand 10 before | Expand all | Expand 10 after
1405 if (node !== null) { 1425 if (node !== null) {
1406 var span = system.compiler.spanFromNode(node, script.uri); 1426 var span = system.compiler.spanFromNode(node, script.uri);
1407 return new Dart2JsLocation(script, span); 1427 return new Dart2JsLocation(script, span);
1408 } else { 1428 } else {
1409 var span = system.compiler.spanFromElement(_variable); 1429 var span = system.compiler.spanFromElement(_variable);
1410 return new Dart2JsLocation(script, span); 1430 return new Dart2JsLocation(script, span);
1411 } 1431 }
1412 } 1432 }
1413 } 1433 }
1414 1434
OLDNEW
« no previous file with comments | « pkg/dartdoc/lib/mirrors_util.dart ('k') | tests/compiler/dart2js/mirrors_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698