| 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 part 'generated_protocol.dart'; | 10 part 'generated_protocol.dart'; |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 */ | 385 */ |
| 386 Object _decodeUnion(String jsonPath, Map json, String field, | 386 Object _decodeUnion(String jsonPath, Map json, String field, |
| 387 Map<String, JsonDecoderCallback> decoders) { | 387 Map<String, JsonDecoderCallback> decoders) { |
| 388 if (json is Map) { | 388 if (json is Map) { |
| 389 if (!json.containsKey(field)) { | 389 if (!json.containsKey(field)) { |
| 390 throw missingKey(jsonPath, field); | 390 throw missingKey(jsonPath, field); |
| 391 } | 391 } |
| 392 var disambiguatorPath = '$jsonPath[${JSON.encode(field)}]'; | 392 var disambiguatorPath = '$jsonPath[${JSON.encode(field)}]'; |
| 393 String disambiguator = _decodeString(disambiguatorPath, json[field]); | 393 String disambiguator = _decodeString(disambiguatorPath, json[field]); |
| 394 if (!decoders.containsKey(disambiguator)) { | 394 if (!decoders.containsKey(disambiguator)) { |
| 395 throw mismatch(disambiguatorPath, 'One of: ${decoders.keys.toList()}', j
son); | 395 throw mismatch( |
| 396 disambiguatorPath, 'One of: ${decoders.keys.toList()}', json); |
| 396 } | 397 } |
| 397 return decoders[disambiguator](jsonPath, json); | 398 return decoders[disambiguator](jsonPath, json); |
| 398 } else { | 399 } else { |
| 399 throw mismatch(jsonPath, 'Map', json); | 400 throw mismatch(jsonPath, 'Map', json); |
| 400 } | 401 } |
| 401 } | 402 } |
| 402 } | 403 } |
| 403 | 404 |
| 404 /** | 405 /** |
| 405 * Instances of the class [Notification] represent a notification from the | 406 * Instances of the class [Notification] represent a notification from the |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 @override | 619 @override |
| 619 dynamic mismatch(String jsonPath, String expected, [Object actual]) { | 620 dynamic mismatch(String jsonPath, String expected, [Object actual]) { |
| 620 StringBuffer buffer = new StringBuffer(); | 621 StringBuffer buffer = new StringBuffer(); |
| 621 buffer.write('Expected to be '); | 622 buffer.write('Expected to be '); |
| 622 buffer.write(expected); | 623 buffer.write(expected); |
| 623 if (actual != null) { | 624 if (actual != null) { |
| 624 buffer.write('; found "'); | 625 buffer.write('; found "'); |
| 625 buffer.write(JSON.encode(actual)); | 626 buffer.write(JSON.encode(actual)); |
| 626 buffer.write('"'); | 627 buffer.write('"'); |
| 627 } | 628 } |
| 628 return new RequestFailure(new Response.invalidParameter( | 629 return new RequestFailure( |
| 629 _request, jsonPath, buffer.toString())); | 630 new Response.invalidParameter(_request, jsonPath, buffer.toString())); |
| 630 } | 631 } |
| 631 | 632 |
| 632 @override | 633 @override |
| 633 dynamic missingKey(String jsonPath, String key) { | 634 dynamic missingKey(String jsonPath, String key) { |
| 634 return new RequestFailure(new Response.invalidParameter( | 635 return new RequestFailure(new Response.invalidParameter( |
| 635 _request, jsonPath, 'Expected to contain key ${JSON.encode(key)}')); | 636 _request, jsonPath, 'Expected to contain key ${JSON.encode(key)}')); |
| 636 } | 637 } |
| 637 } | 638 } |
| 638 | 639 |
| 639 /** | 640 /** |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 /** | 715 /** |
| 715 * Initialize a newly created instance to represent a response to a request | 716 * Initialize a newly created instance to represent a response to a request |
| 716 * with the given [id]. If [_result] is provided, it will be used as the | 717 * with the given [id]. If [_result] is provided, it will be used as the |
| 717 * result; otherwise an empty result will be used. If an [error] is provided | 718 * result; otherwise an empty result will be used. If an [error] is provided |
| 718 * then the response will represent an error condition. | 719 * then the response will represent an error condition. |
| 719 */ | 720 */ |
| 720 Response(this.id, {Map<String, Object> result, this.error}) | 721 Response(this.id, {Map<String, Object> result, this.error}) |
| 721 : _result = result; | 722 : _result = result; |
| 722 | 723 |
| 723 /** | 724 /** |
| 725 * Initialize a newly created instance to represent the |
| 726 * FILE_NOT_ANALYZED error condition. |
| 727 */ |
| 728 Response.fileNotAnalyzed(Request request, String file) |
| 729 : this(request.id, |
| 730 error: new RequestError(RequestErrorCode.FILE_NOT_ANALYZED, |
| 731 'File is not analyzed: $file.')); |
| 732 |
| 733 /** |
| 724 * Initialize a newly created instance to represent the FORMAT_INVALID_FILE | 734 * Initialize a newly created instance to represent the FORMAT_INVALID_FILE |
| 725 * error condition. | 735 * error condition. |
| 726 */ | 736 */ |
| 727 Response.formatInvalidFile(Request request) : this(request.id, | 737 Response.formatInvalidFile(Request request) |
| 728 error: new RequestError(RequestErrorCode.FORMAT_INVALID_FILE, | 738 : this(request.id, |
| 729 'Error during `edit.format`: invalid file.')); | 739 error: new RequestError(RequestErrorCode.FORMAT_INVALID_FILE, |
| 740 'Error during `edit.format`: invalid file.')); |
| 730 | 741 |
| 731 /** | 742 /** |
| 732 * Initialize a newly created instance to represent the FORMAT_WITH_ERROR | 743 * Initialize a newly created instance to represent the FORMAT_WITH_ERROR |
| 733 * error condition. | 744 * error condition. |
| 734 */ | 745 */ |
| 735 Response.formatWithErrors(Request request) : this(request.id, | 746 Response.formatWithErrors(Request request) |
| 736 error: new RequestError(RequestErrorCode.FORMAT_WITH_ERRORS, | 747 : this(request.id, |
| 737 'Error during `edit.format`: source contains syntax errors.')); | 748 error: new RequestError(RequestErrorCode.FORMAT_WITH_ERRORS, |
| 749 'Error during `edit.format`: source contains syntax errors.')); |
| 738 | 750 |
| 739 /** | 751 /** |
| 740 * Initialize a newly created instance based upon the given JSON data | 752 * Initialize a newly created instance based upon the given JSON data |
| 741 */ | 753 */ |
| 742 factory Response.fromJson(Map<String, Object> json) { | 754 factory Response.fromJson(Map<String, Object> json) { |
| 743 try { | 755 try { |
| 744 Object id = json[Response.ID]; | 756 Object id = json[Response.ID]; |
| 745 if (id is! String) { | 757 if (id is! String) { |
| 746 return null; | 758 return null; |
| 747 } | 759 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 759 return new Response(id, error: decodedError, result: decodedResult); | 771 return new Response(id, error: decodedError, result: decodedResult); |
| 760 } catch (exception) { | 772 } catch (exception) { |
| 761 return null; | 773 return null; |
| 762 } | 774 } |
| 763 } | 775 } |
| 764 | 776 |
| 765 /** | 777 /** |
| 766 * Initialize a newly created instance to represent the | 778 * Initialize a newly created instance to represent the |
| 767 * GET_ERRORS_INVALID_FILE error condition. | 779 * GET_ERRORS_INVALID_FILE error condition. |
| 768 */ | 780 */ |
| 769 Response.getErrorsInvalidFile(Request request) : this(request.id, | 781 Response.getErrorsInvalidFile(Request request) |
| 770 error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE, | 782 : this(request.id, |
| 771 'Error during `analysis.getErrors`: invalid file.')); | 783 error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE, |
| 784 'Error during `analysis.getErrors`: invalid file.')); |
| 772 | 785 |
| 773 /** | 786 /** |
| 774 * Initialize a newly created instance to represent the | 787 * Initialize a newly created instance to represent the |
| 775 * GET_NAVIGATION_INVALID_FILE error condition. | 788 * GET_NAVIGATION_INVALID_FILE error condition. |
| 776 */ | 789 */ |
| 777 Response.getNavigationInvalidFile(Request request) : this(request.id, | 790 Response.getNavigationInvalidFile(Request request) |
| 778 error: new RequestError(RequestErrorCode.GET_NAVIGATION_INVALID_FILE, | 791 : this(request.id, |
| 779 'Error during `analysis.getNavigation`: invalid file.')); | 792 error: new RequestError( |
| 793 RequestErrorCode.GET_NAVIGATION_INVALID_FILE, |
| 794 'Error during `analysis.getNavigation`: invalid file.')); |
| 780 | 795 |
| 781 /** | 796 /** |
| 782 * Initialize a newly created instance to represent an error condition caused | 797 * Initialize a newly created instance to represent an error condition caused |
| 783 * by an analysis.reanalyze [request] that specifies an analysis root that is | 798 * by an analysis.reanalyze [request] that specifies an analysis root that is |
| 784 * not in the current list of analysis roots. | 799 * not in the current list of analysis roots. |
| 785 */ | 800 */ |
| 786 Response.invalidAnalysisRoot(Request request, String rootPath) : this( | 801 Response.invalidAnalysisRoot(Request request, String rootPath) |
| 787 request.id, | 802 : this(request.id, |
| 788 error: new RequestError(RequestErrorCode.INVALID_ANALYSIS_ROOT, | 803 error: new RequestError(RequestErrorCode.INVALID_ANALYSIS_ROOT, |
| 789 "Invalid analysis root: $rootPath")); | 804 "Invalid analysis root: $rootPath")); |
| 790 | 805 |
| 791 /** | 806 /** |
| 792 * Initialize a newly created instance to represent an error condition caused | 807 * Initialize a newly created instance to represent an error condition caused |
| 793 * by a [request] that specifies an execution context whose context root does | 808 * by a [request] that specifies an execution context whose context root does |
| 794 * not exist. | 809 * not exist. |
| 795 */ | 810 */ |
| 796 Response.invalidExecutionContext(Request request, String contextId) : this( | 811 Response.invalidExecutionContext(Request request, String contextId) |
| 797 request.id, | 812 : this(request.id, |
| 798 error: new RequestError(RequestErrorCode.INVALID_EXECUTION_CONTEXT, | 813 error: new RequestError(RequestErrorCode.INVALID_EXECUTION_CONTEXT, |
| 799 "Invalid execution context: $contextId")); | 814 "Invalid execution context: $contextId")); |
| 800 | 815 |
| 801 /** | 816 /** |
| 802 * Initialize a newly created instance to represent an error condition caused | 817 * Initialize a newly created instance to represent an error condition caused |
| 803 * by a [request] that had invalid parameter. [path] is the path to the | 818 * by a [request] that had invalid parameter. [path] is the path to the |
| 804 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the | 819 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the |
| 805 * parameter "foo" contained a key "bar" whose value was the wrong type). | 820 * parameter "foo" contained a key "bar" whose value was the wrong type). |
| 806 * [expectation] is a description of the type of data that was expected. | 821 * [expectation] is a description of the type of data that was expected. |
| 807 */ | 822 */ |
| 808 Response.invalidParameter(Request request, String path, String expectation) | 823 Response.invalidParameter(Request request, String path, String expectation) |
| 809 : this(request.id, | 824 : this(request.id, |
| 810 error: new RequestError(RequestErrorCode.INVALID_PARAMETER, | 825 error: new RequestError(RequestErrorCode.INVALID_PARAMETER, |
| 811 "Invalid parameter '$path'. $expectation.")); | 826 "Invalid parameter '$path'. $expectation.")); |
| 812 | 827 |
| 813 /** | 828 /** |
| 814 * Initialize a newly created instance to represent an error condition caused | 829 * Initialize a newly created instance to represent an error condition caused |
| 815 * by a malformed request. | 830 * by a malformed request. |
| 816 */ | 831 */ |
| 817 Response.invalidRequestFormat() : this('', | 832 Response.invalidRequestFormat() |
| 818 error: new RequestError( | 833 : this('', |
| 819 RequestErrorCode.INVALID_REQUEST, 'Invalid request')); | 834 error: new RequestError( |
| 835 RequestErrorCode.INVALID_REQUEST, 'Invalid request')); |
| 820 | 836 |
| 821 /** | 837 /** |
| 822 * Initialize a newly created instance to represent an error condition caused | 838 * Initialize a newly created instance to represent an error condition caused |
| 823 * by a request that requires an index, but indexing is disabled. | 839 * by a request that requires an index, but indexing is disabled. |
| 824 */ | 840 */ |
| 825 Response.noIndexGenerated(Request request) : this(request.id, | 841 Response.noIndexGenerated(Request request) |
| 826 error: new RequestError( | 842 : this(request.id, |
| 827 RequestErrorCode.NO_INDEX_GENERATED, 'Indexing is disabled')); | 843 error: new RequestError( |
| 844 RequestErrorCode.NO_INDEX_GENERATED, 'Indexing is disabled')); |
| 845 |
| 846 /** |
| 847 * Initialize a newly created instance to represent the |
| 848 * ORGANIZE_DIRECTIVES_ERROR error condition. |
| 849 */ |
| 850 Response.organizeDirectivesError(Request request, String message) |
| 851 : this(request.id, |
| 852 error: new RequestError( |
| 853 RequestErrorCode.ORGANIZE_DIRECTIVES_ERROR, message)); |
| 828 | 854 |
| 829 /** | 855 /** |
| 830 * Initialize a newly created instance to represent the | 856 * Initialize a newly created instance to represent the |
| 831 * REFACTORING_REQUEST_CANCELLED error condition. | 857 * REFACTORING_REQUEST_CANCELLED error condition. |
| 832 */ | 858 */ |
| 833 Response.refactoringRequestCancelled(Request request) : this(request.id, | 859 Response.refactoringRequestCancelled(Request request) |
| 834 error: new RequestError( | 860 : this(request.id, |
| 835 RequestErrorCode.REFACTORING_REQUEST_CANCELLED, | 861 error: new RequestError( |
| 836 'The `edit.getRefactoring` request was cancelled.')); | 862 RequestErrorCode.REFACTORING_REQUEST_CANCELLED, |
| 863 'The `edit.getRefactoring` request was cancelled.')); |
| 837 | 864 |
| 838 /** | 865 /** |
| 839 * Initialize a newly created instance to represent the SERVER_ERROR error | 866 * Initialize a newly created instance to represent the SERVER_ERROR error |
| 840 * condition. | 867 * condition. |
| 841 */ | 868 */ |
| 842 factory Response.serverError(Request request, exception, stackTrace) { | 869 factory Response.serverError(Request request, exception, stackTrace) { |
| 843 RequestError error = | 870 RequestError error = |
| 844 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString()); | 871 new RequestError(RequestErrorCode.SERVER_ERROR, exception.toString()); |
| 845 if (stackTrace != null) { | 872 if (stackTrace != null) { |
| 846 error.stackTrace = stackTrace.toString(); | 873 error.stackTrace = stackTrace.toString(); |
| 847 } | 874 } |
| 848 return new Response(request.id, error: error); | 875 return new Response(request.id, error: error); |
| 849 } | 876 } |
| 850 | 877 |
| 851 /** | 878 /** |
| 852 * Initialize a newly created instance to represent the | 879 * Initialize a newly created instance to represent the |
| 853 * SORT_MEMBERS_INVALID_FILE error condition. | 880 * SORT_MEMBERS_INVALID_FILE error condition. |
| 854 */ | 881 */ |
| 855 Response.sortMembersInvalidFile(Request request) : this(request.id, | 882 Response.sortMembersInvalidFile(Request request) |
| 856 error: new RequestError(RequestErrorCode.SORT_MEMBERS_INVALID_FILE, | 883 : this(request.id, |
| 857 'Error during `edit.sortMembers`: invalid file.')); | 884 error: new RequestError(RequestErrorCode.SORT_MEMBERS_INVALID_FILE, |
| 885 'Error during `edit.sortMembers`: invalid file.')); |
| 858 | 886 |
| 859 /** | 887 /** |
| 860 * Initialize a newly created instance to represent the | 888 * Initialize a newly created instance to represent the |
| 861 * SORT_MEMBERS_PARSE_ERRORS error condition. | 889 * SORT_MEMBERS_PARSE_ERRORS error condition. |
| 862 */ | 890 */ |
| 863 Response.sortMembersParseErrors(Request request, int numErrors) : this( | 891 Response.sortMembersParseErrors(Request request, int numErrors) |
| 864 request.id, | 892 : this(request.id, |
| 865 error: new RequestError(RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS, | 893 error: new RequestError(RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS, |
| 866 'Error during `edit.sortMembers`: file has $numErrors scan/parse e
rrors.')); | 894 'Error during `edit.sortMembers`: file has $numErrors scan/parse
errors.')); |
| 867 | 895 |
| 868 /** | 896 /** |
| 869 * Initialize a newly created instance to represent an error condition caused | 897 * Initialize a newly created instance to represent an error condition caused |
| 870 * by a `analysis.setPriorityFiles` [request] that includes one or more files | 898 * by a `analysis.setPriorityFiles` [request] that includes one or more files |
| 871 * that are not being analyzed. | 899 * that are not being analyzed. |
| 872 */ | 900 */ |
| 873 Response.unanalyzedPriorityFiles(String requestId, String fileNames) : this( | 901 Response.unanalyzedPriorityFiles(String requestId, String fileNames) |
| 874 requestId, | 902 : this(requestId, |
| 875 error: new RequestError(RequestErrorCode.UNANALYZED_PRIORITY_FILES, | 903 error: new RequestError(RequestErrorCode.UNANALYZED_PRIORITY_FILES, |
| 876 "Unanalyzed files cannot be a priority: '$fileNames'")); | 904 "Unanalyzed files cannot be a priority: '$fileNames'")); |
| 877 | 905 |
| 878 /** | 906 /** |
| 879 * Initialize a newly created instance to represent an error condition caused | 907 * Initialize a newly created instance to represent an error condition caused |
| 880 * by a [request] that cannot be handled by any known handlers. | 908 * by a [request] that cannot be handled by any known handlers. |
| 881 */ | 909 */ |
| 882 Response.unknownRequest(Request request) : this(request.id, | 910 Response.unknownRequest(Request request) |
| 883 error: new RequestError( | 911 : this(request.id, |
| 884 RequestErrorCode.UNKNOWN_REQUEST, 'Unknown request')); | 912 error: new RequestError( |
| 913 RequestErrorCode.UNKNOWN_REQUEST, 'Unknown request')); |
| 885 | 914 |
| 886 /** | 915 /** |
| 887 * Initialize a newly created instance to represent an error condition caused | 916 * Initialize a newly created instance to represent an error condition caused |
| 888 * by a [request] referencing a source that does not exist. | 917 * by a [request] referencing a source that does not exist. |
| 889 */ | 918 */ |
| 890 Response.unknownSource(Request request) : this(request.id, | 919 Response.unknownSource(Request request) |
| 891 error: new RequestError( | 920 : this(request.id, |
| 892 RequestErrorCode.UNKNOWN_SOURCE, 'Unknown source')); | 921 error: new RequestError( |
| 922 RequestErrorCode.UNKNOWN_SOURCE, 'Unknown source')); |
| 893 | 923 |
| 894 Response.unsupportedFeature(String requestId, String message) : this( | 924 Response.unsupportedFeature(String requestId, String message) |
| 895 requestId, | 925 : this(requestId, |
| 896 error: new RequestError( | 926 error: new RequestError( |
| 897 RequestErrorCode.UNSUPPORTED_FEATURE, message)); | 927 RequestErrorCode.UNSUPPORTED_FEATURE, message)); |
| 898 | 928 |
| 899 /** | 929 /** |
| 900 * Return a table representing the structure of the Json object that will be | 930 * Return a table representing the structure of the Json object that will be |
| 901 * sent to the client to represent this response. | 931 * sent to the client to represent this response. |
| 902 */ | 932 */ |
| 903 Map<String, Object> toJson() { | 933 Map<String, Object> toJson() { |
| 904 Map<String, Object> jsonObject = new HashMap<String, Object>(); | 934 Map<String, Object> jsonObject = new HashMap<String, Object>(); |
| 905 jsonObject[ID] = id; | 935 jsonObject[ID] = id; |
| 906 if (error != null) { | 936 if (error != null) { |
| 907 jsonObject[ERROR] = error.toJson(); | 937 jsonObject[ERROR] = error.toJson(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 990 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 961 hash = hash ^ (hash >> 11); | 991 hash = hash ^ (hash >> 11); |
| 962 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 992 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 963 } | 993 } |
| 964 | 994 |
| 965 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 995 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 966 | 996 |
| 967 static int hash4(a, b, c, d) => | 997 static int hash4(a, b, c, d) => |
| 968 finish(combine(combine(combine(combine(0, a), b), c), d)); | 998 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 969 } | 999 } |
| OLD | NEW |