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

Unified Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 389413002: Use HasToJson when set Reponse/Notification parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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
Index: pkg/analysis_server/lib/src/protocol.dart
diff --git a/pkg/analysis_server/lib/src/protocol.dart b/pkg/analysis_server/lib/src/protocol.dart
index f2c810333bf9d7e31d97450452557dcbe6498429..ee5394209b9aa1390d9800b2fc2518f6518561b3 100644
--- a/pkg/analysis_server/lib/src/protocol.dart
+++ b/pkg/analysis_server/lib/src/protocol.dart
@@ -7,6 +7,8 @@ library protocol;
import 'dart:collection';
import 'dart:convert' show JsonDecoder;
+import 'package:analysis_server/src/collections.dart';
+
/**
* An abstract enumeration.
*/
@@ -616,7 +618,7 @@ class Response {
* Set the value of the result field with the given [name] to the given [value].
*/
void setResult(String name, Object value) {
- result[name] = value;
+ result[name] = _toJson(value);
}
/**
@@ -870,7 +872,7 @@ class Notification {
* Set the value of the parameter with the given [name] to the given [value].
*/
void setParameter(String name, Object value) {
- params[name] = value;
+ params[name] = _toJson(value);
}
/**
@@ -917,3 +919,16 @@ class RequestFailure implements Exception {
*/
RequestFailure(this.response);
}
+
+/**
+ * Returns a JSON presention of [value].
+ */
+_toJson(Object value) {
+ if (value is HasToJson) {
+ return value.toJson();
+ }
+ if (value is Iterable) {
+ return value.map((item) => _toJson(item)).toList();
+ }
+ return value;
+}
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/lib/src/search/search_domain.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698