| OLD | NEW |
| 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 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 750 * related to the error. | 750 * related to the error. |
| 751 */ | 751 */ |
| 752 static const String DATA = 'data'; | 752 static const String DATA = 'data'; |
| 753 | 753 |
| 754 /** | 754 /** |
| 755 * The name of the JSON attribute containing a short description of the error. | 755 * The name of the JSON attribute containing a short description of the error. |
| 756 */ | 756 */ |
| 757 static const String MESSAGE = 'message'; | 757 static const String MESSAGE = 'message'; |
| 758 | 758 |
| 759 /** | 759 /** |
| 760 * An error code indicating a parse error. Invalid JSON was received by the | |
| 761 * server. An error occurred on the server while parsing the JSON text. | |
| 762 */ | |
| 763 static const String CODE_PARSE_ERROR = 'PARSE_ERROR'; | |
| 764 | |
| 765 /** | |
| 766 * An error code indicating that the analysis server has already been | |
| 767 * started (and hence won't accept new connections). | |
| 768 */ | |
| 769 static const String CODE_SERVER_ALREADY_STARTED = 'SERVER_ALREADY_STARTED'; | |
| 770 | |
| 771 /** | |
| 772 * An error code indicating an invalid request. The JSON sent is not a valid | |
| 773 * [Request] object. | |
| 774 */ | |
| 775 static const String CODE_INVALID_REQUEST = 'INVALID_REQUEST'; | |
| 776 | |
| 777 /** | |
| 778 * An error code indicating a method not found. The method does not exist or | |
| 779 * is not currently available. | |
| 780 */ | |
| 781 static const String CODE_METHOD_NOT_FOUND = 'METHOD_NOT_FOUND'; | |
| 782 | |
| 783 /** | |
| 784 * An error code indicating one or more invalid parameters. | |
| 785 */ | |
| 786 static const String CODE_INVALID_PARAMS = 'INVALID_PARAMS'; | |
| 787 | |
| 788 /** | |
| 789 * An error code indicating an internal error. | |
| 790 */ | |
| 791 static const String CODE_INTERNAL_ERROR = 'INTERNAL_ERROR'; | |
| 792 | |
| 793 /** | |
| 794 * An error code indicating a problem using the specified Dart SDK. | 760 * An error code indicating a problem using the specified Dart SDK. |
| 795 */ | 761 */ |
| 796 static const String CODE_SDK_ERROR = 'SDK_ERROR'; | 762 static const String CODE_SDK_ERROR = 'SDK_ERROR'; |
| 797 | 763 |
| 798 /** | 764 /** |
| 799 * An error code indicating a problem during 'analysis.getErrors'. | 765 * An error code indicating a problem during 'analysis.getErrors'. |
| 800 */ | 766 */ |
| 801 static const String CODE_ANALISYS_GET_ERRORS_ERROR = 'ANALYSIS_GET_ERRORS_ERRO
R'; | 767 static const String CODE_ANALISYS_GET_ERRORS_ERROR = 'ANALYSIS_GET_ERRORS_ERRO
R'; |
| 802 | 768 |
| 803 /** | 769 /** |
| 804 * The code that uniquely identifies the error that occurred. | 770 * The code that uniquely identifies the error that occurred. |
| 805 */ | 771 */ |
| 806 final String code; | 772 final RequestErrorCode code; |
| 807 | 773 |
| 808 /** | 774 /** |
| 809 * A short description of the error. | 775 * A short description of the error. |
| 810 */ | 776 */ |
| 811 final String message; | 777 final String message; |
| 812 | 778 |
| 813 /** | 779 /** |
| 814 * A table mapping the names of notification parameters to their values. | 780 * A table mapping the names of notification parameters to their values. |
| 815 */ | 781 */ |
| 816 final Map<String, Object> data = new HashMap<String, Object>(); | 782 final Map<String, Object> data = new HashMap<String, Object>(); |
| 817 | 783 |
| 818 /** | 784 /** |
| 819 * Initialize a newly created [Error] to have the given [code] and [message]. | 785 * Initialize a newly created [Error] to have the given [code] and [message]. |
| 820 */ | 786 */ |
| 821 RequestError(this.code, this.message); | 787 RequestError(this.code, this.message); |
| 822 | 788 |
| 823 /** | 789 /** |
| 824 * Initialize a newly created [Error] from the given JSON. | 790 * Initialize a newly created [Error] from the given JSON. |
| 825 */ | 791 */ |
| 826 factory RequestError.fromJson(Map<String, Object> json) { | 792 factory RequestError.fromJson(Map<String, Object> json) { |
| 827 try { | 793 try { |
| 828 String code = json[RequestError.CODE]; | 794 RequestErrorCode code = new RequestErrorCode(json[RequestError.CODE]); |
| 829 String message = json[RequestError.MESSAGE]; | 795 String message = json[RequestError.MESSAGE]; |
| 830 Map<String, Object> data = json[RequestError.DATA]; | 796 Map<String, Object> data = json[RequestError.DATA]; |
| 831 RequestError requestError = new RequestError(code, message); | 797 RequestError requestError = new RequestError(code, message); |
| 832 if (data != null) { | 798 if (data != null) { |
| 833 data.forEach((String key, Object value) { | 799 data.forEach((String key, Object value) { |
| 834 requestError.setData(key, value); | 800 requestError.setData(key, value); |
| 835 }); | 801 }); |
| 836 } | 802 } |
| 837 return requestError; | 803 return requestError; |
| 838 } catch (exception) { | 804 } catch (exception) { |
| 839 return null; | 805 return null; |
| 840 } | 806 } |
| 841 } | 807 } |
| 842 | 808 |
| 843 /** | 809 /** |
| 844 * Initialize a newly created [Error] to indicate an internal error. | |
| 845 */ | |
| 846 RequestError.internalError() : this(CODE_INTERNAL_ERROR, "Internal error"); | |
| 847 | |
| 848 /** | |
| 849 * Initialize a newly created [Error] to indicate one or more invalid | |
| 850 * parameters. | |
| 851 */ | |
| 852 RequestError.invalidParameters() : this(CODE_INVALID_PARAMS, "Invalid paramete
rs"); | |
| 853 | |
| 854 /** | |
| 855 * Initialize a newly created [Error] to indicate an invalid request. The | |
| 856 * JSON sent is not a valid [Request] object. | |
| 857 */ | |
| 858 RequestError.invalidRequest() : this(CODE_INVALID_REQUEST, "Invalid request"); | |
| 859 | |
| 860 /** | |
| 861 * Initialize a newly created [Error] to indicate that a method was not found. | |
| 862 * Either the method does not exist or is not currently available. | |
| 863 */ | |
| 864 RequestError.methodNotFound() : this(CODE_METHOD_NOT_FOUND, "Method not found"
); | |
| 865 | |
| 866 /** | |
| 867 * Initialize a newly created [Error] to indicate a parse error. Invalid JSON | |
| 868 * was received by the server. An error occurred on the server while parsing | |
| 869 * the JSON text. | |
| 870 */ | |
| 871 RequestError.parseError() : this(CODE_PARSE_ERROR, "Parse error"); | |
| 872 | |
| 873 /** | |
| 874 * Initialize a newly created [Error] to indicate that the analysis server | 810 * Initialize a newly created [Error] to indicate that the analysis server |
| 875 * has already been started (and hence won't accept new connections). | 811 * has already been started (and hence won't accept new connections). |
| 876 */ | 812 */ |
| 877 RequestError.serverAlreadyStarted() | 813 RequestError.serverAlreadyStarted() |
| 878 : this(CODE_SERVER_ALREADY_STARTED, "Server already started"); | 814 : this(RequestErrorCode.SERVER_ALREADY_STARTED, "Server already started"); |
| 879 | 815 |
| 880 /** | 816 /** |
| 881 * Return the value of the data with the given [name], or `null` if there is | 817 * Return the value of the data with the given [name], or `null` if there is |
| 882 * no such data associated with this error. | 818 * no such data associated with this error. |
| 883 */ | 819 */ |
| 884 Object getData(String name) => data[name]; | 820 Object getData(String name) => data[name]; |
| 885 | 821 |
| 886 /** | 822 /** |
| 887 * Set the value of the data with the given [name] to the given [value]. | 823 * Set the value of the data with the given [name] to the given [value]. |
| 888 */ | 824 */ |
| 889 void setData(String name, Object value) { | 825 void setData(String name, Object value) { |
| 890 data[name] = value; | 826 data[name] = value; |
| 891 } | 827 } |
| 892 | 828 |
| 893 /** | 829 /** |
| 894 * Return a table representing the structure of the Json object that will be | 830 * Return a table representing the structure of the Json object that will be |
| 895 * sent to the client to represent this response. | 831 * sent to the client to represent this response. |
| 896 */ | 832 */ |
| 897 Map<String, Object> toJson() { | 833 Map<String, Object> toJson() { |
| 898 Map<String, Object> jsonObject = new HashMap<String, Object>(); | 834 Map<String, Object> jsonObject = new HashMap<String, Object>(); |
| 899 jsonObject[CODE] = code; | 835 jsonObject[CODE] = code.name; |
| 900 jsonObject[MESSAGE] = message; | 836 jsonObject[MESSAGE] = message; |
| 901 if (!data.isEmpty) { | 837 if (!data.isEmpty) { |
| 902 jsonObject[DATA] = data; | 838 jsonObject[DATA] = data; |
| 903 } | 839 } |
| 904 return jsonObject; | 840 return jsonObject; |
| 905 } | 841 } |
| 906 | 842 |
| 907 @override | 843 @override |
| 908 String toString() => toJson().toString(); | 844 String toString() => toJson().toString(); |
| 909 } | 845 } |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 986 | 922 |
| 987 /** | 923 /** |
| 988 * Initialize a newly created instance to represent a response to a request | 924 * Initialize a newly created instance to represent a response to a request |
| 989 * with the given [id]. If [_result] is provided, it will be used as the | 925 * with the given [id]. If [_result] is provided, it will be used as the |
| 990 * result; otherwise an empty result will be used. If an [error] is provided | 926 * result; otherwise an empty result will be used. If an [error] is provided |
| 991 * then the response will represent an error condition. | 927 * then the response will represent an error condition. |
| 992 */ | 928 */ |
| 993 Response(this.id, {Map<String, Object> result, this.error}) | 929 Response(this.id, {Map<String, Object> result, this.error}) |
| 994 : _result = result; | 930 : _result = result; |
| 995 | 931 |
| 996 Response.contextAlreadyExists(Request request) | |
| 997 : this(request.id, error: new RequestError('CONTENT_ALREADY_EXISTS', 'Contex
t already exists')); | |
| 998 | |
| 999 /** | |
| 1000 * Initialize a newly created instance to represent an error condition caused | |
| 1001 * by a [request] referencing a context that does not exist. | |
| 1002 */ | |
| 1003 Response.contextDoesNotExist(Request request) | |
| 1004 : this(request.id, error: new RequestError('NONEXISTENT_CONTEXT', 'Context d
oes not exist')); | |
| 1005 | |
| 1006 /** | 932 /** |
| 1007 * Initialize a newly created instance based upon the given JSON data | 933 * Initialize a newly created instance based upon the given JSON data |
| 1008 */ | 934 */ |
| 1009 factory Response.fromJson(Map<String, Object> json) { | 935 factory Response.fromJson(Map<String, Object> json) { |
| 1010 try { | 936 try { |
| 1011 Object id = json[Response.ID]; | 937 Object id = json[Response.ID]; |
| 1012 if (id is! String) { | 938 if (id is! String) { |
| 1013 return null; | 939 return null; |
| 1014 } | 940 } |
| 1015 Object error = json[Response.ERROR]; | 941 Object error = json[Response.ERROR]; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1030 } | 956 } |
| 1031 | 957 |
| 1032 /** | 958 /** |
| 1033 * Initialize a newly created instance to represent an error condition caused | 959 * Initialize a newly created instance to represent an error condition caused |
| 1034 * by an error during `analysis.getErrors`. | 960 * by an error during `analysis.getErrors`. |
| 1035 */ | 961 */ |
| 1036 Response.getErrorsError(Request request, String message, | 962 Response.getErrorsError(Request request, String message, |
| 1037 Map<String, Object> result) | 963 Map<String, Object> result) |
| 1038 : this( | 964 : this( |
| 1039 request.id, | 965 request.id, |
| 1040 error: new RequestError('GET_ERRORS_ERROR', 'Error during `analysis.getE
rrors`: $message.'), | 966 error: new RequestError(RequestErrorCode.GET_ERRORS_ERROR, 'Error during
`analysis.getErrors`: $message.'), |
| 1041 result: result); | 967 result: result); |
| 1042 | 968 |
| 1043 /** | 969 /** |
| 1044 * Initialize a newly created instance to represent an error condition caused | 970 * Initialize a newly created instance to represent an error condition caused |
| 1045 * by a [request] that had invalid parameter. [path] is the path to the | 971 * by a [request] that had invalid parameter. [path] is the path to the |
| 1046 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the | 972 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the |
| 1047 * parameter "foo" contained a key "bar" whose value was the wrong type). | 973 * parameter "foo" contained a key "bar" whose value was the wrong type). |
| 1048 * [expectation] is a description of the type of data that was expected. | 974 * [expectation] is a description of the type of data that was expected. |
| 1049 */ | 975 */ |
| 1050 Response.invalidParameter(Request request, String path, String expectation) | 976 Response.invalidParameter(Request request, String path, String expectation) |
| 1051 : this(request.id, error: new RequestError('INVALID_PARAMETER', | 977 : this(request.id, error: new RequestError(RequestErrorCode.INVALID_PARAME
TER, |
| 1052 "Expected parameter $path to $expectation")); | 978 "Expected parameter $path to $expectation")); |
| 1053 | 979 |
| 1054 /** | 980 /** |
| 1055 * Initialize a newly created instance to represent an error condition caused | 981 * Initialize a newly created instance to represent an error condition caused |
| 1056 * by a malformed request. | 982 * by a malformed request. |
| 1057 */ | 983 */ |
| 1058 Response.invalidRequestFormat() | 984 Response.invalidRequestFormat() |
| 1059 : this('', error: new RequestError('INVALID_REQUEST', 'Invalid request')); | 985 : this('', error: new RequestError(RequestErrorCode.INVALID_REQUEST, 'Invali
d request')); |
| 1060 | 986 |
| 1061 /** | 987 /** |
| 1062 * Initialize a newly created instance to represent an error condition caused | 988 * Initialize a newly created instance to represent an error condition caused |
| 1063 * by a [request] that does not have a required parameter. | |
| 1064 */ | |
| 1065 Response.missingRequiredParameter(Request request, String parameterName) | |
| 1066 : this(request.id, error: new RequestError('MISSING_PARAMETER', 'Missing req
uired parameter: $parameterName')); | |
| 1067 | |
| 1068 /** | |
| 1069 * Initialize a newly created instance to represent an error condition caused | |
| 1070 * by a `analysis.setPriorityFiles` [request] that includes one or more files | 989 * by a `analysis.setPriorityFiles` [request] that includes one or more files |
| 1071 * that are not being analyzed. | 990 * that are not being analyzed. |
| 1072 */ | 991 */ |
| 1073 Response.unanalyzedPriorityFiles(Request request, String fileNames) | 992 Response.unanalyzedPriorityFiles(Request request, String fileNames) |
| 1074 : this(request.id, error: new RequestError('UNANALYZED_PRIORITY_FILES', "Una
nalyzed files cannot be a priority: '$fileNames'")); | 993 : this(request.id, error: new RequestError(RequestErrorCode.UNANALYZED_PRIOR
ITY_FILES, "Unanalyzed files cannot be a priority: '$fileNames'")); |
| 1075 | |
| 1076 /** | |
| 1077 * Initialize a newly created instance to represent an error condition caused | |
| 1078 * by a [request] that takes a set of analysis options but for which an | |
| 1079 * unknown analysis option was provided. | |
| 1080 */ | |
| 1081 Response.unknownAnalysisOption(Request request, String optionName) | |
| 1082 : this(request.id, error: new RequestError('UNKNOWN_ANALYSIS_OPTION', 'Unkno
wn analysis option: "$optionName"')); | |
| 1083 | |
| 1084 /** | |
| 1085 * Initialize a newly created instance to represent an error condition caused | |
| 1086 * by a `analysis.setSubscriptions` [request] that includes an unknown | |
| 1087 * analysis service name. | |
| 1088 */ | |
| 1089 Response.unknownAnalysisService(Request request, String name) | |
| 1090 : this(request.id, error: new RequestError('UNKNOWN_ANALYSIS_SERVICE', 'Unkn
own analysis service: "$name"')); | |
| 1091 | |
| 1092 /** | |
| 1093 * Initialize a newly created instance to represent an error condition caused | |
| 1094 * by a `analysis.updateOptions` [request] that includes an unknown analysis | |
| 1095 * option. | |
| 1096 */ | |
| 1097 Response.unknownOptionName(Request request, String optionName) | |
| 1098 : this(request.id, error: new RequestError('UNKNOWN_OPTION_NAME', 'Unknown a
nalysis option: "$optionName"')); | |
| 1099 | 994 |
| 1100 /** | 995 /** |
| 1101 * Initialize a newly created instance to represent an error condition caused | 996 * Initialize a newly created instance to represent an error condition caused |
| 1102 * by a [request] that cannot be handled by any known handlers. | 997 * by a [request] that cannot be handled by any known handlers. |
| 1103 */ | 998 */ |
| 1104 Response.unknownRequest(Request request) | 999 Response.unknownRequest(Request request) |
| 1105 : this(request.id, error: new RequestError('UNKNOWN_REQUEST', 'Unknown reque
st')); | 1000 : this(request.id, error: new RequestError(RequestErrorCode.UNKNOWN_REQUEST,
'Unknown request')); |
| 1106 | 1001 |
| 1107 Response.unsupportedFeature(String requestId, String message) | 1002 Response.unsupportedFeature(String requestId, String message) |
| 1108 : this(requestId, error: new RequestError('UNSUPPORTED_FEATURE', message)); | 1003 : this(requestId, error: new RequestError(RequestErrorCode.UNSUPPORTED_FEATU
RE, message)); |
| 1109 | 1004 |
| 1110 /** | 1005 /** |
| 1111 * Return a table representing the structure of the Json object that will be | 1006 * Return a table representing the structure of the Json object that will be |
| 1112 * sent to the client to represent this response. | 1007 * sent to the client to represent this response. |
| 1113 */ | 1008 */ |
| 1114 Map<String, Object> toJson() { | 1009 Map<String, Object> toJson() { |
| 1115 Map<String, Object> jsonObject = new HashMap<String, Object>(); | 1010 Map<String, Object> jsonObject = new HashMap<String, Object>(); |
| 1116 jsonObject[ID] = id; | 1011 jsonObject[ID] = id; |
| 1117 if (error != null) { | 1012 if (error != null) { |
| 1118 jsonObject[ERROR] = error.toJson(); | 1013 jsonObject[ERROR] = error.toJson(); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1157 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 1052 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 1158 hash = hash ^ (hash >> 11); | 1053 hash = hash ^ (hash >> 11); |
| 1159 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 1054 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 1160 } | 1055 } |
| 1161 | 1056 |
| 1162 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 1057 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 1163 | 1058 |
| 1164 static int hash4(a, b, c, d) => | 1059 static int hash4(a, b, c, d) => |
| 1165 finish(combine(combine(combine(combine(0, a), b), c), d)); | 1060 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 1166 } | 1061 } |
| OLD | NEW |