@@ -21,10 +21,10 @@ export 'package:analyzer_plugin/protocol/protocol.dart' show Enum;
2121class Notification {
2222 /// The name of the JSON attribute containing the name of the event that
2323 /// triggered the notification.
24- static const String EVENT = 'event' ;
24+ static const String eventAttributeName = 'event' ;
2525
2626 /// The name of the JSON attribute containing the result values.
27- static const String PARAMS = 'params' ;
27+ static const String paramsAttributeName = 'params' ;
2828
2929 /// The name of the event that triggered the notification.
3030 final String event;
@@ -41,40 +41,35 @@ class Notification {
4141 /// Initialize a newly created instance based on the given JSON data.
4242 factory Notification .fromJson (Map <Object ?, Object ?> json) {
4343 return Notification (
44- json[Notification .EVENT ] as String ,
45- json[Notification .PARAMS ] as Map <String , Object ?>? ,
44+ json[Notification .eventAttributeName ] as String ,
45+ json[Notification .paramsAttributeName ] as Map <String , Object ?>? ,
4646 );
4747 }
4848
49- /// Return a table representing the structure of the Json object that will be
49+ /// Returns a table representing the structure of the JSON object that will be
5050 /// sent to the client to represent this response.
51- Map <String , Object > toJson () {
52- var jsonObject = < String , Object > {};
53- jsonObject[EVENT ] = event;
54- var params = this .params;
55- if (params != null ) {
56- jsonObject[PARAMS ] = params;
57- }
58- return jsonObject;
59- }
51+ Map <String , Object > toJson () => {
52+ eventAttributeName: event,
53+ paramsAttributeName: ? params,
54+ };
6055}
6156
6257/// A request that was received from the client.
6358///
6459/// Clients may not extend, implement or mix-in this class.
6560class Request extends RequestOrResponse {
6661 /// The name of the JSON attribute containing the id of the request.
67- static const String ID = 'id' ;
62+ static const String idAttributeName = 'id' ;
6863
6964 /// The name of the JSON attribute containing the name of the request.
70- static const String METHOD = 'method' ;
65+ static const String methodAttributeName = 'method' ;
7166
7267 /// The name of the JSON attribute containing the request parameters.
73- static const String PARAMS = 'params' ;
68+ static const String paramsAttributeName = 'params' ;
7469
7570 /// The name of the optional JSON attribute indicating the time (milliseconds
7671 /// since epoch) at which the client made the request.
77- static const String CLIENT_REQUEST_TIME = 'clientRequestTime' ;
72+ static const String clientRequestTimeAttributeName = 'clientRequestTime' ;
7873
7974 /// The unique identifier used to identify this request.
8075 @override
@@ -123,21 +118,14 @@ class Request extends RequestOrResponse {
123118 _equalMaps (params, other.params);
124119 }
125120
126- /// Return a table representing the structure of the Json object that will be
121+ /// Returns a table representing the structure of the JSON object that will be
127122 /// sent to the client to represent this response.
128- Map <String , Object > toJson () {
129- var jsonObject = < String , Object > {};
130- jsonObject[ID ] = id;
131- jsonObject[METHOD ] = method;
132- if (params.isNotEmpty) {
133- jsonObject[PARAMS ] = params;
134- }
135- var clientRequestTime = this .clientRequestTime;
136- if (clientRequestTime != null ) {
137- jsonObject[CLIENT_REQUEST_TIME ] = clientRequestTime;
138- }
139- return jsonObject;
140- }
123+ Map <String , Object > toJson () => {
124+ idAttributeName: id,
125+ methodAttributeName: method,
126+ if (params.isNotEmpty) paramsAttributeName: params,
127+ clientRequestTimeAttributeName: ? clientRequestTime,
128+ };
141129
142130 bool _equalLists (List <Object ?> first, List <Object ?> second) {
143131 var length = first.length;
@@ -189,60 +177,60 @@ class Request extends RequestOrResponse {
189177 return first == second;
190178 }
191179
192- /// Return a request parsed from the given json , or `null` if the [data] is
193- /// not a valid json representation of a request. The [ data] is expected to
194- /// have the following format:
180+ /// Returns a request parsed from the given JSON [result] , or `null` if the
181+ /// data is not a valid JSON representation of a request. The data is expected
182+ /// to have the following format:
195183 ///
196- /// {
197- /// 'clientRequestTime': millisecondsSinceEpoch
198- /// 'id': String,
199- /// 'method': methodName,
200- /// 'params': {
201- /// parameter_name: value
184+ /// {
185+ /// 'clientRequestTime': millisecondsSinceEpoch
186+ /// 'id': String,
187+ /// 'method': methodName,
188+ /// 'params': {
189+ /// parameter_name: value
190+ /// }
202191 /// }
203- /// }
204192 ///
205- /// where both the parameters and clientRequestTime are optional.
193+ /// where both the parameters and ` clientRequestTime` are optional.
206194 ///
207195 /// The parameters can contain any number of name/value pairs. The
208- /// clientRequestTime must be an int representing the time at which the client
209- /// issued the request (milliseconds since epoch).
196+ /// ` clientRequestTime` must be an int representing the time at which the
197+ /// client issued the request (milliseconds since epoch).
210198 static Request ? fromJson (Map <String , Object ?> result) {
211- var id = result[Request .ID ];
212- var method = result[Request .METHOD ];
199+ var id = result[Request .idAttributeName ];
200+ var method = result[Request .methodAttributeName ];
213201 if (id is ! String || method is ! String ) {
214202 return null ;
215203 }
216- var time = result[Request .CLIENT_REQUEST_TIME ];
204+ var time = result[Request .clientRequestTimeAttributeName ];
217205 if (time is ! int ? ) {
218206 return null ;
219207 }
220- var params = result[Request .PARAMS ];
208+ var params = result[Request .paramsAttributeName ];
221209 if (params is Map <String , Object ?>? ) {
222210 return Request (id, method, params, time);
223211 } else {
224212 return null ;
225213 }
226214 }
227215
228- /// Return a request parsed from the given [data] , or `null` if the [data] is
229- /// not a valid json representation of a request. The [data] is expected to
216+ /// Returns a request parsed from the given [data] , or `null` if the [data] is
217+ /// not a valid JSON representation of a request. The [data] is expected to
230218 /// have the following format:
231219 ///
232- /// {
233- /// 'clientRequestTime': millisecondsSinceEpoch
234- /// 'id': String,
235- /// 'method': methodName,
236- /// 'params': {
237- /// parameter_name: value
220+ /// {
221+ /// 'clientRequestTime': millisecondsSinceEpoch
222+ /// 'id': String,
223+ /// 'method': methodName,
224+ /// 'params': {
225+ /// parameter_name: value
226+ /// }
238227 /// }
239- /// }
240228 ///
241- /// where both the parameters and clientRequestTime are optional.
229+ /// where both the parameters and ` clientRequestTime` are optional.
242230 ///
243231 /// The parameters can contain any number of name/value pairs. The
244- /// clientRequestTime must be an int representing the time at which the client
245- /// issued the request (milliseconds since epoch).
232+ /// ` clientRequestTime` must be an int representing the time at which the
233+ /// client issued the request (milliseconds since epoch).
246234 static Request ? fromString (String data) {
247235 try {
248236 var result = json.decode (data);
@@ -293,13 +281,13 @@ abstract class RequestOrResponse {
293281class Response extends RequestOrResponse {
294282 /// The name of the JSON attribute containing the id of the request for which
295283 /// this is a response.
296- static const String ID = 'id' ;
284+ static const String idAttributeName = 'id' ;
297285
298286 /// The name of the JSON attribute containing the error message.
299- static const String ERROR = 'error' ;
287+ static const String errorAttributeName = 'error' ;
300288
301289 /// The name of the JSON attribute containing the result values.
302- static const String RESULT = 'result' ;
290+ static const String resultAttributeName = 'result' ;
303291
304292 /// The unique identifier used to identify the request that this response is
305293 /// associated with.
@@ -315,7 +303,7 @@ class Response extends RequestOrResponse {
315303 Map <String , Object ?>? result;
316304
317305 /// Initialize a newly created instance to represent a response to a request
318- /// with the given [id] . If [_result ] is provided, it will be used as the
306+ /// with the given [id] . If [result ] is provided, it will be used as the
319307 /// result; otherwise an empty result will be used. If an [error] is provided
320308 /// then the response will represent an error condition.
321309 Response (this .id, {this .result, this .error});
@@ -615,30 +603,22 @@ class Response extends RequestOrResponse {
615603
616604 /// Return a table representing the structure of the Json object that will be
617605 /// sent to the client to represent this response.
618- Map <String , Object > toJson () {
619- var jsonObject = < String , Object > {};
620- jsonObject[ID ] = id;
621- var error = this .error;
622- if (error != null ) {
623- jsonObject[ERROR ] = error.toJson (clientUriConverter: null );
624- }
625- var result = this .result;
626- if (result != null ) {
627- jsonObject[RESULT ] = result;
628- }
629- return jsonObject;
630- }
606+ Map <String , Object > toJson () => {
607+ idAttributeName: id,
608+ errorAttributeName: ? error? .toJson (clientUriConverter: null ),
609+ resultAttributeName: ? result,
610+ };
631611
632612 /// Initialize a newly created instance based on the given JSON data.
633613 static Response ? fromJson (Map <String , Object ?> json) {
634614 try {
635- var id = json[Response .ID ];
615+ var id = json[Response .idAttributeName ];
636616 if (id is ! String ) {
637617 return null ;
638618 }
639619
640620 RequestError ? decodedError;
641- var error = json[Response .ERROR ];
621+ var error = json[Response .errorAttributeName ];
642622 if (error is Map ) {
643623 decodedError = RequestError .fromJson (
644624 ResponseDecoder (null ),
@@ -649,7 +629,7 @@ class Response extends RequestOrResponse {
649629 }
650630
651631 Map <String , Object ?>? decodedResult;
652- var result = json[Response .RESULT ];
632+ var result = json[Response .resultAttributeName ];
653633 if (result is Map <String , Object ?>) {
654634 decodedResult = result;
655635 }
0 commit comments