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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/docgen/lib/src/models.dart » ('j') | pkg/docgen/test/constant_argument_test.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/docgen/lib/src/model_helpers.dart
diff --git a/pkg/docgen/lib/src/model_helpers.dart b/pkg/docgen/lib/src/model_helpers.dart
index 678fa19394cd84fbddc2dfeff3954eadee302452..1820b1d97770346d340df4e9ea5ac62b98b1f5eb 100644
--- a/pkg/docgen/lib/src/model_helpers.dart
+++ b/pkg/docgen/lib/src/model_helpers.dart
@@ -17,6 +17,41 @@ import 'library_helpers.dart' show includePrivateMembers;
import 'models.dart';
import 'package_helpers.dart';
+String getDefaultValue(ParameterMirror mirror) {
+ if (!mirror.hasDefaultValue) return null;
+ return getDefaultValueFromConstMirror(mirror.defaultValue);
+}
+
+String getDefaultValueFromConstMirror(
+ dart2js_mirrors.Dart2JsConstantMirror valueMirror) {
+
+ if (valueMirror is dart2js_mirrors.Dart2JsStringConstantMirror) {
+ return '"${valueMirror.reflectee}"';
+ }
+
+ if (valueMirror is dart2js_mirrors.Dart2JsListConstantMirror) {
+ var buffer = new StringBuffer('[');
+
+ var values = new Iterable.generate(valueMirror.length,
+ (i) => valueMirror.getElement(i))
+ .map((e) => getDefaultValueFromConstMirror(e));
+
+ buffer.writeAll(values, ', ');
+
+ buffer.write(']');
+ return buffer.toString();
+ }
+
+ if (valueMirror is dart2js_mirrors.Dart2JsMapConstantMirror) {
+ // TODO(kevmoo) Handle non-empty case
+ if (valueMirror.length == 0) return '{}';
+ }
+
+ // TODO(kevmoo) Handle consts of non-core types
+
+ return '${valueMirror}';
+}
+
/// Returns a list of meta annotations assocated with a mirror.
List<Annotation> createAnnotations(DeclarationMirror mirror,
Library owningLibrary) {
« 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