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

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

Issue 235883016: pkg/docgen: support better const rendering of String, List, and empty Map (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.model_helpers; 5 library docgen.model_helpers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rrors.dart' 9 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/dart2js_mi rrors.dart'
10 as dart2js_mirrors; 10 as dart2js_mirrors;
11 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart' 11 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/mirrors_ut il.dart'
12 as dart2js_util; 12 as dart2js_util;
13 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart'; 13 import '../../../../sdk/lib/_internal/compiler/implementation/mirrors/source_mir rors.dart';
14 import '../../../../sdk/lib/_internal/libraries.dart'; 14 import '../../../../sdk/lib/_internal/libraries.dart';
15 15
16 import 'library_helpers.dart' show includePrivateMembers; 16 import 'library_helpers.dart' show includePrivateMembers;
17 import 'models.dart'; 17 import 'models.dart';
18 import 'package_helpers.dart'; 18 import 'package_helpers.dart';
19 19
20 String getDefaultValue(ParameterMirror mirror) {
21 if (!mirror.hasDefaultValue) return null;
22 return getDefaultValueFromConstMirror(mirror.defaultValue);
23 }
24
25 String getDefaultValueFromConstMirror(
26 dart2js_mirrors.Dart2JsConstantMirror valueMirror) {
27
28 if (valueMirror is dart2js_mirrors.Dart2JsStringConstantMirror) {
29 return '"${valueMirror.reflectee}"';
30 }
31
32 if (valueMirror is dart2js_mirrors.Dart2JsListConstantMirror) {
33 var buffer = new StringBuffer('[');
34
35 var values = new Iterable.generate(valueMirror.length,
36 (i) => valueMirror.getElement(i))
37 .map((e) => getDefaultValueFromConstMirror(e));
38
39 buffer.writeAll(values, ', ');
40
41 buffer.write(']');
42 return buffer.toString();
43 }
44
45 if (valueMirror is dart2js_mirrors.Dart2JsMapConstantMirror) {
46 // TODO(kevmoo) Handle non-empty case
47 if (valueMirror.length == 0) return '{}';
48 }
49
50 // TODO(kevmoo) Handle consts of non-core types
51
52 return '${valueMirror}';
53 }
54
20 /// Returns a list of meta annotations assocated with a mirror. 55 /// Returns a list of meta annotations assocated with a mirror.
21 List<Annotation> createAnnotations(DeclarationMirror mirror, 56 List<Annotation> createAnnotations(DeclarationMirror mirror,
22 Library owningLibrary) { 57 Library owningLibrary) {
23 var annotationMirrors = mirror.metadata 58 var annotationMirrors = mirror.metadata
24 .where((e) => e is dart2js_mirrors.Dart2JsConstructedConstantMirror); 59 .where((e) => e is dart2js_mirrors.Dart2JsConstructedConstantMirror);
25 var annotations = []; 60 var annotations = [];
26 annotationMirrors.forEach((annotation) { 61 annotationMirrors.forEach((annotation) {
27 var docgenAnnotation = new Annotation(annotation, owningLibrary); 62 var docgenAnnotation = new Annotation(annotation, owningLibrary);
28 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf( 63 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf(
29 docgenAnnotation.mirror))) { 64 docgenAnnotation.mirror))) {
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 // the time. 255 // the time.
221 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; 256 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
222 if (sdkLibrary != null) { 257 if (sdkLibrary != null) {
223 return !sdkLibrary.documented; 258 return !sdkLibrary.documented;
224 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( 259 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf(
225 mirror).contains('._')) { 260 mirror).contains('._')) {
226 return true; 261 return true;
227 } 262 }
228 return false; 263 return false;
229 } 264 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/lib/src/models.dart » ('j') | pkg/docgen/test/constant_argument_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698