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

Side by Side Diff: pkg/analysis_server/lib/src/protocol.dart

Issue 456613004: Integration test search.getTypeHierarchy and make some minor fixes. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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_services/json.dart'; 10 import 'package:analysis_services/json.dart';
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 */ 494 */
495 final String id; 495 final String id;
496 496
497 /** 497 /**
498 * The error that was caused by attempting to handle the request, or `null` if 498 * The error that was caused by attempting to handle the request, or `null` if
499 * there was no error. 499 * there was no error.
500 */ 500 */
501 final RequestError error; 501 final RequestError error;
502 502
503 /** 503 /**
504 * A table mapping the names of result fields to their values. The table 504 * A table mapping the names of result fields to their values. Should be
505 * should be empty if there was an error. 505 * null if there is no result to send.
506 */ 506 */
507 final Map<String, Object> result = new HashMap<String, Object>(); 507 Map<String, Object> result;
508 508
509 /** 509 /**
510 * Initialize a newly created instance to represent a response to a request 510 * Initialize a newly created instance to represent a response to a request
511 * with the given [id]. If an [error] is provided then the response will 511 * with the given [id]. If an [error] is provided then the response will
512 * represent an error condition. 512 * represent an error condition.
513 */ 513 */
514 Response(this.id, [this.error]); 514 Response(this.id, [this.error]);
515 515
516 /** 516 /**
517 * Initialize a newly created instance to represent an error condition caused 517 * Initialize a newly created instance to represent an error condition caused
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 return response; 624 return response;
625 } catch (exception) { 625 } catch (exception) {
626 return null; 626 return null;
627 } 627 }
628 } 628 }
629 629
630 /** 630 /**
631 * Return the value of the result field with the given [name]. 631 * Return the value of the result field with the given [name].
632 */ 632 */
633 Object getResult(String name) { 633 Object getResult(String name) {
634 return result[name]; 634 return result == null ? null : result[name];
635 } 635 }
636 636
637 /** 637 /**
638 * Set the value of the result field with the given [name] to the given [value ]. 638 * Set the value of the result field with the given [name] to the given [value ].
639 */ 639 */
640 void setResult(String name, Object value) { 640 void setResult(String name, Object value) {
641 if (result == null) {
642 result = new HashMap<String, Object>();
643 }
641 result[name] = _toJson(value); 644 result[name] = _toJson(value);
642 } 645 }
643 646
644 /** 647 /**
648 * Set the result to be an empty map.
649 */
650 void setEmptyResult() {
651 result = new HashMap<String, Object>();
652 }
653
654 /**
645 * Return a table representing the structure of the Json object that will be 655 * Return a table representing the structure of the Json object that will be
646 * sent to the client to represent this response. 656 * sent to the client to represent this response.
647 */ 657 */
648 Map<String, Object> toJson() { 658 Map<String, Object> toJson() {
649 Map<String, Object> jsonObject = new HashMap<String, Object>(); 659 Map<String, Object> jsonObject = new HashMap<String, Object>();
650 jsonObject[ID] = id; 660 jsonObject[ID] = id;
651 if (error != null) { 661 if (error != null) {
652 jsonObject[ERROR] = error.toJson(); 662 jsonObject[ERROR] = error.toJson();
653 } 663 }
654 if (!result.isEmpty) { 664 if (result != null) {
655 jsonObject[RESULT] = result; 665 jsonObject[RESULT] = result;
656 } 666 }
657 return jsonObject; 667 return jsonObject;
658 } 668 }
659 } 669 }
660 670
661 /** 671 /**
662 * Instances of the class [RequestError] represent information about an error 672 * Instances of the class [RequestError] represent information about an error
663 * that occurred while attempting to respond to a [Request]. 673 * that occurred while attempting to respond to a [Request].
664 */ 674 */
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 */ 955 */
946 _toJson(Object value) { 956 _toJson(Object value) {
947 if (value is HasToJson) { 957 if (value is HasToJson) {
948 return value.toJson(); 958 return value.toJson();
949 } 959 }
950 if (value is Iterable) { 960 if (value is Iterable) {
951 return value.map((item) => _toJson(item)).toList(); 961 return value.map((item) => _toJson(item)).toList();
952 } 962 }
953 return value; 963 return value;
954 } 964 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698