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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
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 protocol; 5 library protocol;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert' show JsonDecoder; 8 import 'dart:convert' show JsonDecoder;
9 9
10 import 'package:analysis_server/src/collections.dart';
11
10 /** 12 /**
11 * An abstract enumeration. 13 * An abstract enumeration.
12 */ 14 */
13 abstract class Enum2<E extends Enum2> implements Comparable<E> { 15 abstract class Enum2<E extends Enum2> implements Comparable<E> {
14 /** 16 /**
15 * The name of this enum constant, as declared in the enum declaration. 17 * The name of this enum constant, as declared in the enum declaration.
16 */ 18 */
17 final String name; 19 final String name;
18 20
19 /** 21 /**
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after
609 * Return the value of the result field with the given [name]. 611 * Return the value of the result field with the given [name].
610 */ 612 */
611 Object getResult(String name) { 613 Object getResult(String name) {
612 return result[name]; 614 return result[name];
613 } 615 }
614 616
615 /** 617 /**
616 * Set the value of the result field with the given [name] to the given [value ]. 618 * Set the value of the result field with the given [name] to the given [value ].
617 */ 619 */
618 void setResult(String name, Object value) { 620 void setResult(String name, Object value) {
619 result[name] = value; 621 result[name] = _toJson(value);
620 } 622 }
621 623
622 /** 624 /**
623 * Return a table representing the structure of the Json object that will be 625 * Return a table representing the structure of the Json object that will be
624 * sent to the client to represent this response. 626 * sent to the client to represent this response.
625 */ 627 */
626 Map<String, Object> toJson() { 628 Map<String, Object> toJson() {
627 Map<String, Object> jsonObject = new HashMap<String, Object>(); 629 Map<String, Object> jsonObject = new HashMap<String, Object>();
628 jsonObject[ID] = id; 630 jsonObject[ID] = id;
629 if (error != null) { 631 if (error != null) {
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
863 /** 865 /**
864 * Return the value of the parameter with the given [name], or `null` if there 866 * Return the value of the parameter with the given [name], or `null` if there
865 * is no such parameter associated with this notification. 867 * is no such parameter associated with this notification.
866 */ 868 */
867 Object getParameter(String name) => params[name]; 869 Object getParameter(String name) => params[name];
868 870
869 /** 871 /**
870 * Set the value of the parameter with the given [name] to the given [value]. 872 * Set the value of the parameter with the given [name] to the given [value].
871 */ 873 */
872 void setParameter(String name, Object value) { 874 void setParameter(String name, Object value) {
873 params[name] = value; 875 params[name] = _toJson(value);
874 } 876 }
875 877
876 /** 878 /**
877 * Return a table representing the structure of the Json object that will be 879 * Return a table representing the structure of the Json object that will be
878 * sent to the client to represent this response. 880 * sent to the client to represent this response.
879 */ 881 */
880 Map<String, Object> toJson() { 882 Map<String, Object> toJson() {
881 Map<String, Object> jsonObject = new HashMap<String, Object>(); 883 Map<String, Object> jsonObject = new HashMap<String, Object>();
882 jsonObject[EVENT] = event; 884 jsonObject[EVENT] = event;
883 if (!params.isEmpty) { 885 if (!params.isEmpty) {
(...skipping 26 matching lines...) Expand all
910 /** 912 /**
911 * The response to be returned as a result of the failure. 913 * The response to be returned as a result of the failure.
912 */ 914 */
913 final Response response; 915 final Response response;
914 916
915 /** 917 /**
916 * Initialize a newly created exception to return the given reponse. 918 * Initialize a newly created exception to return the given reponse.
917 */ 919 */
918 RequestFailure(this.response); 920 RequestFailure(this.response);
919 } 921 }
922
923 /**
924 * Returns a JSON presention of [value].
925 */
926 _toJson(Object value) {
927 if (value is HasToJson) {
928 return value.toJson();
929 }
930 if (value is Iterable) {
931 return value.map((item) => _toJson(item)).toList();
932 }
933 return value;
934 }
OLDNEW
« 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