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

Unified Diff: pkg/docgen/lib/src/models/indexable.dart

Issue 245673002: pkg/docgen: a bunch of cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
Index: pkg/docgen/lib/src/models/indexable.dart
diff --git a/pkg/docgen/lib/src/models/indexable.dart b/pkg/docgen/lib/src/models/indexable.dart
index da93220245c96646c232855481aacc8ad4259696..658f4d174e00048b983aff25e90521639356ea01 100644
--- a/pkg/docgen/lib/src/models/indexable.dart
+++ b/pkg/docgen/lib/src/models/indexable.dart
@@ -10,7 +10,6 @@ import '../exports/mirrors_util.dart' as dart2js_util;
import '../exports/source_mirrors.dart';
import '../library_helpers.dart';
-import 'dummy_mirror.dart';
import 'library.dart';
import 'mirror_based.dart';
import 'model_helpers.dart';
@@ -30,7 +29,14 @@ abstract class Indexable<TMirror extends DeclarationMirror>
Library get owningLibrary => owner.owningLibrary;
- String get qualifiedName => fileName;
kevmoo 2014/04/21 19:22:19 Moved impl of fileName to qualifiedName + docs. R
+ /// The reference to this element based on where it is printed as a
+ /// documentation file and also the unique URL to refer to this item.
+ ///
+ /// The qualified name (for URL purposes) and the file name are the same,
+ /// of the form packageName/ClassName or packageName/ClassName.methodName.
+ /// This defines both the URL and the directory structure.
+ String get qualifiedName => packagePrefix + ownerPrefix + name;
+
final TMirror mirror;
final bool isPrivate;
/// The comment text pre-resolution. We keep this around because inherited
@@ -41,14 +47,21 @@ abstract class Indexable<TMirror extends DeclarationMirror>
: this.mirror = mirror,
this.isPrivate = isHidden(mirror) {
- var map = mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)];
- if (map == null) map = new Map<String, Set<Indexable>>();
+ var mirrorQualifiedName = dart2js_util.qualifiedNameOf(this.mirror);
+
+ var map = _mirrorToDocgen.putIfAbsent(mirrorQualifiedName,
+ () => new Map<String, Indexable>());
+
+ var added = false;
+ map.putIfAbsent(owner.docName, () {
+ added = true;
+ return this;
+ });
- var set = map[owner.docName];
- if (set == null) set = new Set<Indexable>();
- set.add(this);
- map[owner.docName] = set;
- mirrorToDocgen[dart2js_util.qualifiedNameOf(this.mirror)] = map;
+ if (!added) {
kevmoo 2014/04/21 19:22:19 Ensure we don't create duplicates
+ throw new StateError('An indexable has already been stored for '
+ '${owner.docName}');
+ }
}
/// Returns this object's qualified name, but following the conventions
@@ -71,14 +84,6 @@ abstract class Indexable<TMirror extends DeclarationMirror>
String findElementInScope(String name) =>
findElementInScopeWithPrefix(name, packagePrefix);
- /// The reference to this element based on where it is printed as a
- /// documentation file and also the unique URL to refer to this item.
- ///
- /// The qualified name (for URL purposes) and the file name are the same,
- /// of the form packageName/ClassName or packageName/ClassName.methodName.
- /// This defines both the URL and the directory structure.
- String get fileName => packagePrefix + ownerPrefix + name;
-
/// The full docName of the owner element, appended with a '.' for this
/// object's name to be appended.
String get ownerPrefix => owner.docName != '' ? owner.docName + '.' : '';
@@ -118,7 +123,7 @@ abstract class Indexable<TMirror extends DeclarationMirror>
/// is defined. Ex: The owner for a top level class, would be its enclosing
/// library. The owner of a local variable in a method would be the enclosing
/// method.
- Indexable get owner => new DummyMirror(mirror.owner);
kevmoo 2014/04/21 19:22:19 Now abstract
+ Indexable get owner;
/// Generates MDN comments from database.json.
String getMdnComment();
@@ -191,3 +196,19 @@ abstract class Indexable<TMirror extends DeclarationMirror>
/// object wraps. (Workaround for the fact that Types are not first class.)
bool isValidMirror(DeclarationMirror mirror);
}
+
+/// Index of all the dart2js mirrors examined to corresponding MirrorBased
+/// docgen objects.
+///
+/// Used for lookup because of the dart2js mirrors exports
+/// issue. The second level map is indexed by owner docName for faster lookup.
+/// Why two levels of lookup? Speed, man. Speed.
+final Map<String, Map<String, Indexable>> _mirrorToDocgen =
+ new Map<String, Map<String, Indexable>>();
+
+Iterable<Indexable> get allIndexables =>
+ _mirrorToDocgen.values.expand((map) => map.values);
+
+Map<String, Indexable> lookupIndexableMap(DeclarationMirror mirror) {
+ return _mirrorToDocgen[dart2js_util.qualifiedNameOf(mirror)];
+}

Powered by Google App Engine
This is Rietveld 408576698