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

Side by Side Diff: pkg/docgen/lib/src/utils.dart

Issue 209563002: pkg/docgen: the big refactor (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: silly Created 6 years, 9 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 | « pkg/docgen/lib/src/package_helpers.dart ('k') | pkg/docgen/lib/src/viewer.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library docgen.utils;
6
7 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart';
8 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart'
9 as dart2js_util;
10 import '../../../../sdk/lib/_internal/libraries.dart';
11
12 // HTML escaped version of '<' character.
13 const LESS_THAN = '&lt;';
14
15 /// A declaration is private if itself is private, or the owner is private.
16 // Issue(12202) - A declaration is public even if it's owner is private.
17 bool isHidden(DeclarationMirror mirror) {
18 if (mirror is LibraryMirror) {
19 return _isLibraryPrivate(mirror);
20 } else if (mirror.owner is LibraryMirror) {
21 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) ||
22 mirror.isNameSynthetic);
23 } else {
24 return (mirror.isPrivate || isHidden(mirror.owner) ||
25 mirror.isNameSynthetic);
26 }
27 }
28
29 /// Returns true if a library name starts with an underscore, and false
30 /// otherwise.
31 ///
32 /// An example that starts with _ is _js_helper.
33 /// An example that contains ._ is dart._collection.dev
34 bool _isLibraryPrivate(LibraryMirror mirror) {
35 // This method is needed because LibraryMirror.isPrivate returns `false` all
36 // the time.
37 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
38 if (sdkLibrary != null) {
39 return !sdkLibrary.documented;
40 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf(
41 mirror).contains('._')) {
42 return true;
43 }
44 return false;
45 }
46
47 /// Transforms the map by calling toMap on each value in it.
48 Map recurseMap(Map inputMap) {
49 var outputMap = {};
50 inputMap.forEach((key, value) {
51 if (value is Map) {
52 outputMap[key] = recurseMap(value);
53 } else {
54 outputMap[key] = value.toMap();
55 }
56 });
57 return outputMap;
58 }
59
60 Map filterMap(Map map, Function test) {
61 var exported = new Map();
62 map.forEach((key, value) {
63 if (test(key, value)) exported[key] = value;
64 });
65 return exported;
66 }
67
68 /// Chunk the provided name into individual parts to be resolved. We take a
69 /// simplistic approach to chunking, though, we break at " ", ",", "&lt;"
70 /// and ">". All other characters are grouped into the name to be resolved.
71 /// As a result, these characters will all be treated as part of the item to
72 /// be resolved (aka the * is interpreted literally as a *, not as an
73 /// indicator for bold <em>.
74 List<String> tokenizeComplexReference(String name) {
75 var tokens = [];
76 var append = false;
77 var index = 0;
78 while (index < name.length) {
79 if (name.indexOf(LESS_THAN, index) == index) {
80 tokens.add(LESS_THAN);
81 append = false;
82 index += LESS_THAN.length;
83 } else if (name[index] == ' ' || name[index] == ',' || name[index] == '>') {
84 tokens.add(name[index]);
85 append = false;
86 index++;
87 } else {
88 if (append) {
89 tokens[tokens.length - 1] = tokens.last + name[index];
90 } else {
91 tokens.add(name[index]);
92 append = true;
93 }
94 index++;
95 }
96 }
97 return tokens;
98 }
99
100 typedef DeclarationMirror LookupFunction(DeclarationSourceMirror declaration,
101 String name);
102
103 /// For a given name, determine if we need to resolve it as a qualified name
104 /// or a simple name in the source mirors.
105 LookupFunction determineLookupFunc(String name) => name.contains('.') ?
106 dart2js_util.lookupQualifiedInScope :
107 (mirror, name) => mirror.lookupInScope(name);
OLDNEW
« no previous file with comments | « pkg/docgen/lib/src/package_helpers.dart ('k') | pkg/docgen/lib/src/viewer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698