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

Side by Side Diff: pkg/docgen/lib/src/library_helpers.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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 docgen.library_helpers; 5 library docgen.library_helpers;
6 6
7 import 'package:logging/logging.dart'; 7 import 'package:logging/logging.dart';
8 import 'package:markdown/markdown.dart' as markdown; 8 import 'package:markdown/markdown.dart' as markdown;
9 9
10 import 'exports/source_mirrors.dart'; 10 import 'exports/source_mirrors.dart';
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 /// The dart:core library, which contains all types that are always available 50 /// The dart:core library, which contains all types that are always available
51 /// without import. 51 /// without import.
52 Library _coreLibrary; 52 Library _coreLibrary;
53 53
54 /// Set of libraries declared in the SDK, so libraries that can be accessed 54 /// Set of libraries declared in the SDK, so libraries that can be accessed
55 /// when running dart by default. 55 /// when running dart by default.
56 Iterable<LibraryMirror> get sdkLibraries => _sdkLibraries; 56 Iterable<LibraryMirror> get sdkLibraries => _sdkLibraries;
57 Iterable<LibraryMirror> _sdkLibraries; 57 Iterable<LibraryMirror> _sdkLibraries;
58 58
59 /// Index of all the dart2js mirrors examined to corresponding MirrorBased
60 /// docgen objects.
61 ///
62 /// Used for lookup because of the dart2js mirrors exports
63 /// issue. The second level map is indexed by owner docName for faster lookup.
64 /// Why two levels of lookup? Speed, man. Speed.
65 final Map<String, Map<String, Set<Indexable>>> mirrorToDocgen = new Map<String,
kevmoo 2014/04/21 19:22:19 Moved to Indexable.dart
66 Map<String, Set<Indexable>>>();
67
68 ////// Top level resolution functions 59 ////// Top level resolution functions
69 /// Converts all [foo] references in comments to <a>libraryName.foo</a>. 60 /// Converts all [foo] references in comments to <a>libraryName.foo</a>.
70 markdown.Node globalFixReference(String name) { 61 markdown.Node globalFixReference(String name) {
71 // Attempt the look up the whole name up in the scope. 62 // Attempt the look up the whole name up in the scope.
72 String elementName = findElementInScopeWithPrefix(name, ''); 63 String elementName = findElementInScopeWithPrefix(name, '');
73 if (elementName != null) { 64 if (elementName != null) {
74 return new markdown.Element.text('a', elementName); 65 return new markdown.Element.text('a', elementName);
75 } 66 }
76 return fixComplexReference(name); 67 return fixComplexReference(name);
77 } 68 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 135 }
145 136
146 /// Given a Dart2jsMirror, find the corresponding Docgen [MirrorBased] object. 137 /// Given a Dart2jsMirror, find the corresponding Docgen [MirrorBased] object.
147 /// 138 ///
148 /// We have this global lookup function to avoid re-implementing looking up 139 /// We have this global lookup function to avoid re-implementing looking up
149 /// the scoping rules for comment resolution here (it is currently done in 140 /// the scoping rules for comment resolution here (it is currently done in
150 /// mirrors). If no corresponding MirrorBased object is found, we return a 141 /// mirrors). If no corresponding MirrorBased object is found, we return a
151 /// [DummyMirror] that simply returns the original mirror's qualifiedName 142 /// [DummyMirror] that simply returns the original mirror's qualifiedName
152 /// while behaving like a MirrorBased object. 143 /// while behaving like a MirrorBased object.
153 Indexable getDocgenObject(DeclarationMirror mirror, [Indexable owner]) { 144 Indexable getDocgenObject(DeclarationMirror mirror, [Indexable owner]) {
154 Map<String, Set<Indexable>> docgenObj = 145 Map<String, Indexable> docgenObj = lookupIndexableMap(mirror);
155 mirrorToDocgen[dart2js_util.qualifiedNameOf(mirror)]; 146
156 if (docgenObj == null) { 147 if (docgenObj == null) {
157 return new DummyMirror(mirror, owner); 148 return new DummyMirror(mirror, owner);
158 } 149 }
159 150
160 var setToExamine = new Set(); 151 var setToExamine = new Set();
161 if (owner != null) { 152 if (owner != null) {
162 var firstSet = docgenObj[owner.docName]; 153 var firstSet = docgenObj[owner.docName];
163 if (firstSet != null) setToExamine.addAll(firstSet); 154 if (firstSet != null) setToExamine.add(firstSet);
164 if (_coreLibrary != null && docgenObj[_coreLibrary.docName] != null) { 155 if (_coreLibrary != null && docgenObj[_coreLibrary.docName] != null) {
165 setToExamine.addAll(docgenObj[_coreLibrary.docName]); 156 setToExamine.add(docgenObj[_coreLibrary.docName]);
166 } 157 }
167 } else { 158 } else {
168 for (var value in docgenObj.values) { 159 setToExamine.addAll(docgenObj.values);
169 setToExamine.addAll(value);
170 }
171 } 160 }
172 161
173 Set<Indexable> results = new Set<Indexable>(); 162 Set<Indexable> results = new Set<Indexable>();
174 for (Indexable indexable in setToExamine) { 163 for (Indexable indexable in setToExamine) {
175 if (indexable.mirror.qualifiedName == mirror.qualifiedName && 164 if (indexable.mirror.qualifiedName == mirror.qualifiedName &&
176 indexable.isValidMirror(mirror)) { 165 indexable.isValidMirror(mirror)) {
177 results.add(indexable); 166 results.add(indexable);
178 } 167 }
179 } 168 }
180 169
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 append = true; 214 append = true;
226 } 215 }
227 index++; 216 index++;
228 } 217 }
229 } 218 }
230 return tokens; 219 return tokens;
231 } 220 }
232 221
233 // HTML escaped version of '<' character. 222 // HTML escaped version of '<' character.
234 const _LESS_THAN = '&lt;'; 223 const _LESS_THAN = '&lt;';
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698