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

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

Issue 574683002: Use ConstExp for storing constants. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 6 years, 2 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 | « no previous file | pkg/docgen/test/constant_argument_test.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.model_helpers; 5 library docgen.model_helpers;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 8
9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors; 9 import '../exports/dart2js_mirrors.dart' as dart2js_mirrors;
10 import '../exports/mirrors_util.dart' as dart2js_util; 10 import '../exports/mirrors_util.dart' as dart2js_util;
(...skipping 24 matching lines...) Expand all
35 'constructors': recurseMap(_filterMap(mapToExpand, 35 'constructors': recurseMap(_filterMap(mapToExpand,
36 (key, val) => val.mirror.isConstructor)), 36 (key, val) => val.mirror.isConstructor)),
37 'operators': recurseMap(_filterMap(mapToExpand, 37 'operators': recurseMap(_filterMap(mapToExpand,
38 (key, val) => val.mirror.isOperator)), 38 (key, val) => val.mirror.isOperator)),
39 'methods': recurseMap(_filterMap(mapToExpand, 39 'methods': recurseMap(_filterMap(mapToExpand,
40 (key, val) => val.mirror.isRegularMethod && !val.mirror.isOperator)) 40 (key, val) => val.mirror.isRegularMethod && !val.mirror.isOperator))
41 }; 41 };
42 42
43 String getDefaultValue(ParameterMirror mirror) { 43 String getDefaultValue(ParameterMirror mirror) {
44 if (!mirror.hasDefaultValue) return null; 44 if (!mirror.hasDefaultValue) return null;
45 return getDefaultValueFromConstMirror(mirror.defaultValue); 45 return '${mirror.defaultValue}';
46 } 46 }
47 47
48 String getDefaultValueFromConstMirror( 48 // TODO(johnniwinther): Use the `ConstExp` classes instead of `ResolvedNode`.
49 dart2js_mirrors.Dart2JsConstantMirror valueMirror) {
50
51 if (valueMirror is dart2js_mirrors.Dart2JsStringConstantMirror) {
52 return '"${valueMirror.reflectee}"';
53 }
54
55 if (valueMirror is dart2js_mirrors.Dart2JsListConstantMirror) {
56 var buffer = new StringBuffer('[');
57
58 var values = new Iterable.generate(valueMirror.length,
59 (i) => valueMirror.getElement(i))
60 .map((e) => getDefaultValueFromConstMirror(e));
61
62 buffer.writeAll(values, ', ');
63
64 buffer.write(']');
65 return buffer.toString();
66 }
67
68 if (valueMirror is dart2js_mirrors.Dart2JsMapConstantMirror) {
69 // TODO(kevmoo) Handle non-empty case
70 if (valueMirror.length == 0) return '{}';
71 }
72
73 // TODO(kevmoo) Handle consts of non-core types
74
75 return '${valueMirror}';
76 }
77
78 /// Returns a list of meta annotations assocated with a mirror. 49 /// Returns a list of meta annotations assocated with a mirror.
79 List<Annotation> createAnnotations(DeclarationMirror mirror, 50 List<Annotation> createAnnotations(DeclarationMirror mirror,
80 Library owningLibrary) { 51 Library owningLibrary) {
81 var annotations = []; 52 var annotations = [];
82 for (dart2js_mirrors.ResolvedNode node in 53 for (dart2js_mirrors.ResolvedNode node in
83 dart2js_mirrors.BackDoor.metadataSyntaxOf(mirror)) { 54 dart2js_mirrors.BackDoor.metadataSyntaxOf(mirror)) {
84 var docgenAnnotation = new Annotation(node, owningLibrary); 55 var docgenAnnotation = new Annotation(node, owningLibrary);
85 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf( 56 if (!_SKIPPED_ANNOTATIONS.contains(dart2js_util.qualifiedNameOf(
86 docgenAnnotation.mirror))) { 57 docgenAnnotation.mirror))) {
87 annotations.add(docgenAnnotation); 58 annotations.add(docgenAnnotation);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 // the time. 252 // the time.
282 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)]; 253 var sdkLibrary = LIBRARIES[dart2js_util.nameOf(mirror)];
283 if (sdkLibrary != null) { 254 if (sdkLibrary != null) {
284 return !sdkLibrary.documented; 255 return !sdkLibrary.documented;
285 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf( 256 } else if (dart2js_util.nameOf(mirror).startsWith('_') || dart2js_util.nameOf(
286 mirror).contains('._')) { 257 mirror).contains('._')) {
287 return true; 258 return true;
288 } 259 }
289 return false; 260 return false;
290 } 261 }
OLDNEW
« no previous file with comments | « no previous file | pkg/docgen/test/constant_argument_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698