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 8cee0f6d5b0f8160ec5e7a8da587b47cba342e76..8a15ebe9e9418a6863555ef60c323afff56e7e8f 100644 |
--- a/pkg/analysis_server/lib/src/protocol.dart |
+++ b/pkg/analysis_server/lib/src/protocol.dart |
@@ -518,12 +518,12 @@ class Request { |
* have the following format: |
* |
* { |
+ * 'clientRequestTime': millisecondsSinceEpoch |
* 'id': String, |
* 'method': methodName, |
* 'params': { |
* paramter_name: value |
* } |
- * 'clientRequestTime': millisecondsSinceEpoch |
* } |
* |
* where both the parameters and clientRequestTime are optional. |
@@ -534,30 +534,53 @@ class Request { |
factory Request.fromString(String data) { |
try { |
var result = JSON.decode(data); |
- if (result is! Map) { |
- return null; |
- } |
- var id = result[Request.ID]; |
- var method = result[Request.METHOD]; |
- if (id is! String || method is! String) { |
- return null; |
- } |
- var time = result[Request.CLIENT_REQUEST_TIME]; |
- if (time != null && time is! int) { |
- return null; |
- } |
- var params = result[Request.PARAMS]; |
- if (params is Map || params == null) { |
- return new Request(id, method, params, time); |
- } else { |
- return null; |
+ if (result is Map) { |
+ return new Request.fromJson(result); |
} |
+ return null; |
} catch (exception) { |
return null; |
} |
} |
/** |
+ * Return a request parsed from the given json, or `null` if the [data] is |
+ * not a valid json representation of a request. The [data] is expected to |
+ * have the following format: |
+ * |
+ * { |
+ * 'clientRequestTime': millisecondsSinceEpoch |
+ * 'id': String, |
+ * 'method': methodName, |
+ * 'params': { |
+ * paramter_name: value |
+ * } |
+ * } |
+ * |
+ * where both the parameters and clientRequestTime are optional. |
+ * The parameters can contain any number of name/value pairs. |
+ * The clientRequestTime must be an int representing the time at which |
+ * the client issued the request (milliseconds since epoch). |
+ */ |
+ factory Request.fromJson(Map<String, dynamic> result) { |
+ var id = result[Request.ID]; |
+ var method = result[Request.METHOD]; |
+ if (id is! String || method is! String) { |
+ return null; |
+ } |
+ var time = result[Request.CLIENT_REQUEST_TIME]; |
+ if (time != null && time is! int) { |
+ return null; |
+ } |
+ var params = result[Request.PARAMS]; |
+ if (params is Map || params == null) { |
+ return new Request(id, method, params, time); |
+ } else { |
+ return null; |
+ } |
+ } |
+ |
+ /** |
* Return a table representing the structure of the Json object that will be |
* sent to the client to represent this response. |
*/ |