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

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

Issue 530583004: Rename Error to RequestError in analysis server API. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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'; 8 import 'dart:convert';
9 9
10 import 'package:analysis_server/src/computer/element.dart' show 10 import 'package:analysis_server/src/computer/element.dart' show
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 @override 728 @override
729 dynamic missingKey(String jsonPath, String key) { 729 dynamic missingKey(String jsonPath, String key) {
730 return new RequestFailure( 730 return new RequestFailure(
731 new Response.invalidParameter( 731 new Response.invalidParameter(
732 _request, 732 _request,
733 jsonPath, 733 jsonPath,
734 'contain key ${JSON.encode(key)}')); 734 'contain key ${JSON.encode(key)}'));
735 } 735 }
736 } 736 }
737 737
738 /**
739 * Instances of the class [RequestError] represent information about an error
740 * that occurred while attempting to respond to a [Request].
741 */
742 class RequestError {
743 /**
744 * The name of the JSON attribute containing the code that uniquely identifies
745 * the error that occurred.
746 */
747 static const String CODE = 'code';
748
749 /**
750 * The name of the JSON attribute containing an object with additional data
751 * related to the error.
752 */
753 static const String DATA = 'data';
754
755 /**
756 * The name of the JSON attribute containing a short description of the error.
757 */
758 static const String MESSAGE = 'message';
759
760 /**
761 * An error code indicating a problem using the specified Dart SDK.
762 */
763 static const String CODE_SDK_ERROR = 'SDK_ERROR';
764
765 /**
766 * An error code indicating a problem during 'analysis.getErrors'.
767 */
768 static const String CODE_ANALISYS_GET_ERRORS_ERROR = 'ANALYSIS_GET_ERRORS_ERRO R';
769
770 /**
771 * The code that uniquely identifies the error that occurred.
772 */
773 final RequestErrorCode code;
774
775 /**
776 * A short description of the error.
777 */
778 final String message;
779
780 /**
781 * A table mapping the names of notification parameters to their values.
782 */
783 final Map<String, Object> data = new HashMap<String, Object>();
784
785 /**
786 * Initialize a newly created [Error] to have the given [code] and [message].
787 */
788 RequestError(this.code, this.message);
789
790 /**
791 * Initialize a newly created [Error] from the given JSON.
792 */
793 factory RequestError.fromJson(Map<String, Object> json) {
794 try {
795 RequestErrorCode code = new RequestErrorCode(json[RequestError.CODE]);
796 String message = json[RequestError.MESSAGE];
797 Map<String, Object> data = json[RequestError.DATA];
798 RequestError requestError = new RequestError(code, message);
799 if (data != null) {
800 data.forEach((String key, Object value) {
801 requestError.setData(key, value);
802 });
803 }
804 return requestError;
805 } catch (exception) {
806 return null;
807 }
808 }
809
810 /**
811 * Initialize a newly created [Error] to indicate that the analysis server
812 * has already been started (and hence won't accept new connections).
813 */
814 RequestError.serverAlreadyStarted()
815 : this(RequestErrorCode.SERVER_ALREADY_STARTED, "Server already started");
816
817 /**
818 * Return the value of the data with the given [name], or `null` if there is
819 * no such data associated with this error.
820 */
821 Object getData(String name) => data[name];
822
823 /**
824 * Set the value of the data with the given [name] to the given [value].
825 */
826 void setData(String name, Object value) {
827 data[name] = value;
828 }
829
830 /**
831 * Return a table representing the structure of the Json object that will be
832 * sent to the client to represent this response.
833 */
834 Map<String, Object> toJson() {
835 Map<String, Object> jsonObject = new HashMap<String, Object>();
836 jsonObject[CODE] = code.name;
837 jsonObject[MESSAGE] = message;
838 if (!data.isEmpty) {
839 jsonObject[DATA] = data;
840 }
841 return jsonObject;
842 }
843
844 @override
845 String toString() => toJson().toString();
846 }
847
848 738
849 /** 739 /**
850 * Instances of the class [RequestFailure] represent an exception that occurred 740 * Instances of the class [RequestFailure] represent an exception that occurred
851 * during the handling of a request that requires that an error be returned to 741 * during the handling of a request that requires that an error be returned to
852 * the client. 742 * the client.
853 */ 743 */
854 class RequestFailure implements Exception { 744 class RequestFailure implements Exception {
855 /** 745 /**
856 * The response to be returned as a result of the failure. 746 * The response to be returned as a result of the failure.
857 */ 747 */
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 */ 825 */
936 factory Response.fromJson(Map<String, Object> json) { 826 factory Response.fromJson(Map<String, Object> json) {
937 try { 827 try {
938 Object id = json[Response.ID]; 828 Object id = json[Response.ID];
939 if (id is! String) { 829 if (id is! String) {
940 return null; 830 return null;
941 } 831 }
942 Object error = json[Response.ERROR]; 832 Object error = json[Response.ERROR];
943 RequestError decodedError; 833 RequestError decodedError;
944 if (error is Map) { 834 if (error is Map) {
945 decodedError = new RequestError.fromJson(error); 835 decodedError = new RequestError.fromJson(new ResponseDecoder(),
836 '.error', error);
946 } 837 }
947 Object result = json[Response.RESULT]; 838 Object result = json[Response.RESULT];
948 Map<String, Object> decodedResult; 839 Map<String, Object> decodedResult;
949 if (result is Map) { 840 if (result is Map) {
950 decodedResult = result; 841 decodedResult = result;
951 } 842 }
952 return new Response(id, error: decodedError, 843 return new Response(id, error: decodedError,
953 result: decodedResult); 844 result: decodedResult);
954 } catch (exception) { 845 } catch (exception) {
955 return null; 846 return null;
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
1053 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); 944 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3));
1054 hash = hash ^ (hash >> 11); 945 hash = hash ^ (hash >> 11);
1055 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); 946 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15));
1056 } 947 }
1057 948
1058 static int hash2(a, b) => finish(combine(combine(0, a), b)); 949 static int hash2(a, b) => finish(combine(combine(0, a), b));
1059 950
1060 static int hash4(a, b, c, d) => 951 static int hash4(a, b, c, d) =>
1061 finish(combine(combine(combine(combine(0, a), b), c), d)); 952 finish(combine(combine(combine(combine(0, a), b), c), d));
1062 } 953 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/generated_protocol.dart ('k') | pkg/analysis_server/lib/src/socket_server.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698