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

Side by Side Diff: pkg/docgen/lib/src/model_helpers.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/library_helpers.dart ('k') | pkg/docgen/lib/src/models.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) 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.utils; 5 library docgen.model_helpers;
6 6
7 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart'; 7 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rrors.dart'
8 as dart2js_mirrors;
8 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart' 9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart'
9 as dart2js_util; 10 as dart2js_util;
11 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart';
10 import '../../../../sdk/lib/_internal/libraries.dart'; 12 import '../../../../sdk/lib/_internal/libraries.dart';
11 13
12 // HTML escaped version of '<' character. 14 import 'models.dart';
13 const LESS_THAN = '&lt;'; 15 import 'package_helpers.dart';
16
17 /// Returns a list of meta annotations assocated with a mirror.
18 List<Annotation> createAnnotations(DeclarationMirror mirror, Library
19 owningLibrary) {
20 var annotationMirrors = mirror.metadata.where((e) => e is
21 dart2js_mirrors.Dart2JsConstructedConstantMirror);
22 var annotations = [];
23 annotationMirrors.forEach((annotation) {
24 var docgenAnnotation = new Annotation(annotation, owningLibrary);
25 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf(
26 docgenAnnotation.mirror))) {
27 annotations.add(docgenAnnotation);
28 }
29 });
30 return annotations;
31 }
14 32
15 /// A declaration is private if itself is private, or the owner is private. 33 /// 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. 34 // Issue(12202) - A declaration is public even if it's owner is private.
17 bool isHidden(DeclarationMirror mirror) { 35 bool isHidden(DeclarationSourceMirror mirror) {
18 if (mirror is LibraryMirror) { 36 if (mirror is LibraryMirror) {
19 return _isLibraryPrivate(mirror); 37 return _isLibraryPrivate(mirror);
20 } else if (mirror.owner is LibraryMirror) { 38 } else if (mirror.owner is LibraryMirror) {
21 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) || 39 return (mirror.isPrivate || _isLibraryPrivate(mirror.owner) ||
22 mirror.isNameSynthetic); 40 mirror.isNameSynthetic);
23 } else { 41 } else {
24 return (mirror.isPrivate || isHidden(mirror.owner) || 42 return (mirror.isPrivate || isHidden(mirror.owner) ||
25 mirror.isNameSynthetic); 43 mirror.isNameSynthetic);
26 } 44 }
27 } 45 }
28 46
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. 47 /// Transforms the map by calling toMap on each value in it.
48 Map recurseMap(Map inputMap) { 48 Map recurseMap(Map inputMap) {
49 var outputMap = {}; 49 var outputMap = {};
50 inputMap.forEach((key, value) { 50 inputMap.forEach((key, value) {
51 if (value is Map) { 51 if (value is Map) {
52 outputMap[key] = recurseMap(value); 52 outputMap[key] = recurseMap(value);
53 } else { 53 } else {
54 outputMap[key] = value.toMap(); 54 outputMap[key] = value.toMap();
55 } 55 }
56 }); 56 });
57 return outputMap; 57 return outputMap;
58 } 58 }
59 59
60 Map filterMap(Map map, Function test) { 60 Map filterMap(Map map, Function test) {
61 var exported = new Map(); 61 var exported = new Map();
62 map.forEach((key, value) { 62 map.forEach((key, value) {
63 if (test(key, value)) exported[key] = value; 63 if (test(key, value)) exported[key] = value;
64 }); 64 });
65 return exported; 65 return exported;
66 } 66 }
67 67
68 /// Chunk the provided name into individual parts to be resolved. We take a 68 /// Read a pubspec and return the library name given a [LibraryMirror].
69 /// simplistic approach to chunking, though, we break at " ", ",", "&lt;" 69 String getPackageName(LibraryMirror mirror) {
70 /// and ">". All other characters are grouped into the name to be resolved. 70 if (mirror.uri.scheme != 'file') return '';
71 /// As a result, these characters will all be treated as part of the item to 71 var rootdir = getPackageDirectory(mirror);
72 /// be resolved (aka the * is interpreted literally as a *, not as an 72 if (rootdir == null) return '';
73 /// indicator for bold <em>. 73 return packageNameFor(rootdir);
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 } 74 }
99 75
100 typedef DeclarationMirror LookupFunction(DeclarationSourceMirror declaration, 76 /// Annotations that we do not display in the viewer.
101 String name); 77 const List<String> _SKIPPED_ANNOTATIONS = const [
78 'metadata.DocsEditable', '_js_helper.JSName', '_js_helper.Creates',
79 '_js_helper.Returns'
80 ];
102 81
103 /// For a given name, determine if we need to resolve it as a qualified name 82 /// Returns true if a library name starts with an underscore, and false
104 /// or a simple name in the source mirors. 83 /// otherwise.
105 LookupFunction determineLookupFunc(String name) => name.contains('.') ? 84 ///
106 dart2js_util.lookupQualifiedInScope : 85 /// An example that starts with _ is _js_helper.
107 (mirror, name) => mirror.lookupInScope(name); 86 /// An example that contains ._ is dart._collection.dev
87 bool _isLibraryPrivate(dart2js_mirrors.Dart2JsLibraryMirror mirror) {
88 // This method is needed because LibraryMirror.isPrivate returns `false` all
89 // the time.
90 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
91 if (sdkLibrary != null) {
92 return !sdkLibrary.documented;
93 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf(
94 mirror).contains('._')) {
95 return true;
96 }
97 return false;
98 }
OLDNEW
« no previous file with comments | « pkg/docgen/lib/src/library_helpers.dart ('k') | pkg/docgen/lib/src/models.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698