| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 while (index < edits.length && edits[index].offset > sourceEdit.offset) { | 62 while (index < edits.length && edits[index].offset > sourceEdit.offset) { |
| 63 index++; | 63 index++; |
| 64 } | 64 } |
| 65 edits.insert(index, sourceEdit); | 65 edits.insert(index, sourceEdit); |
| 66 } | 66 } |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Adds [edit] to the [FileEdit] for the given [file]. | 69 * Adds [edit] to the [FileEdit] for the given [file]. |
| 70 */ | 70 */ |
| 71 void _addEditToSourceChange(SourceChange change, String file, int fileStamp, | 71 void _addEditToSourceChange(SourceChange change, String file, int fileStamp, |
| 72 SourceEdit edit) { | 72 SourceEdit edit) { |
| 73 SourceFileEdit fileEdit = change.getFileEdit(file); | 73 SourceFileEdit fileEdit = change.getFileEdit(file); |
| 74 if (fileEdit == null) { | 74 if (fileEdit == null) { |
| 75 fileEdit = new SourceFileEdit(file, fileStamp); | 75 fileEdit = new SourceFileEdit(file, fileStamp); |
| 76 change.addFileEdit(fileEdit); | 76 change.addFileEdit(fileEdit); |
| 77 } | 77 } |
| 78 fileEdit.add(edit); | 78 fileEdit.add(edit); |
| 79 } | 79 } |
| 80 | 80 |
| 81 | 81 |
| 82 void _addElementEditToSourceChange(SourceChange change, engine.Element element, | 82 void _addElementEditToSourceChange(SourceChange change, engine.Element element, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 String _applySequence(String code, Iterable<SourceEdit> edits) { | 163 String _applySequence(String code, Iterable<SourceEdit> edits) { |
| 164 edits.forEach((SourceEdit edit) { | 164 edits.forEach((SourceEdit edit) { |
| 165 code = edit.apply(code); | 165 code = edit.apply(code); |
| 166 }); | 166 }); |
| 167 return code; | 167 return code; |
| 168 } | 168 } |
| 169 | 169 |
| 170 /** | 170 /** |
| 171 * Map an element kind from the analyzer engine to a [CompletionSuggestionKind]. | 171 * Map an element kind from the analyzer engine to a [CompletionSuggestionKind]. |
| 172 */ | 172 */ |
| 173 CompletionSuggestionKind _completionSuggestionKindFromElementKind(engine.Element
Kind kind) { | 173 CompletionSuggestionKind |
| 174 _completionSuggestionKindFromElementKind(engine.ElementKind kind) { |
| 174 // ElementKind.ANGULAR_FORMATTER, | 175 // ElementKind.ANGULAR_FORMATTER, |
| 175 // ElementKind.ANGULAR_COMPONENT, | 176 // ElementKind.ANGULAR_COMPONENT, |
| 176 // ElementKind.ANGULAR_CONTROLLER, | 177 // ElementKind.ANGULAR_CONTROLLER, |
| 177 // ElementKind.ANGULAR_DIRECTIVE, | 178 // ElementKind.ANGULAR_DIRECTIVE, |
| 178 // ElementKind.ANGULAR_PROPERTY, | 179 // ElementKind.ANGULAR_PROPERTY, |
| 179 // ElementKind.ANGULAR_SCOPE_PROPERTY, | 180 // ElementKind.ANGULAR_SCOPE_PROPERTY, |
| 180 // ElementKind.ANGULAR_SELECTOR, | 181 // ElementKind.ANGULAR_SELECTOR, |
| 181 // ElementKind.ANGULAR_VIEW, | 182 // ElementKind.ANGULAR_VIEW, |
| 182 if (kind == engine.ElementKind.CLASS) return CompletionSuggestionKind.CLASS; | 183 if (kind == engine.ElementKind.CLASS) return CompletionSuggestionKind.CLASS; |
| 183 // ElementKind.COMPILATION_UNIT, | 184 // ElementKind.COMPILATION_UNIT, |
| 184 if (kind == engine.ElementKind.CONSTRUCTOR) return CompletionSuggestionKind.CO
NSTRUCTOR; | 185 if (kind == |
| 186 engine.ElementKind.CONSTRUCTOR) return CompletionSuggestionKind.CONSTRUCTO
R; |
| 185 // ElementKind.DYNAMIC, | 187 // ElementKind.DYNAMIC, |
| 186 // ElementKind.EMBEDDED_HTML_SCRIPT, | 188 // ElementKind.EMBEDDED_HTML_SCRIPT, |
| 187 // ElementKind.ERROR, | 189 // ElementKind.ERROR, |
| 188 // ElementKind.EXPORT, | 190 // ElementKind.EXPORT, |
| 189 // ElementKind.EXTERNAL_HTML_SCRIPT, | 191 // ElementKind.EXTERNAL_HTML_SCRIPT, |
| 190 if (kind == engine.ElementKind.FIELD) return CompletionSuggestionKind.FIELD; | 192 if (kind == engine.ElementKind.FIELD) return CompletionSuggestionKind.FIELD; |
| 191 if (kind == engine.ElementKind.FUNCTION) return CompletionSuggestionKind.FUNCT
ION; | 193 if (kind == |
| 192 if (kind == engine.ElementKind.FUNCTION_TYPE_ALIAS) return CompletionSuggestio
nKind.FUNCTION_TYPE_ALIAS; | 194 engine.ElementKind.FUNCTION) return CompletionSuggestionKind.FUNCTION; |
| 195 if (kind == |
| 196 engine.ElementKind.FUNCTION_TYPE_ALIAS) return |
| 197 CompletionSuggestionKind.FUNCTION_TYPE_ALIAS; |
| 193 if (kind == engine.ElementKind.GETTER) return CompletionSuggestionKind.GETTER; | 198 if (kind == engine.ElementKind.GETTER) return CompletionSuggestionKind.GETTER; |
| 194 // ElementKind.HTML, | 199 // ElementKind.HTML, |
| 195 if (kind == engine.ElementKind.IMPORT) return CompletionSuggestionKind.IMPORT; | 200 if (kind == engine.ElementKind.IMPORT) return CompletionSuggestionKind.IMPORT; |
| 196 // ElementKind.LABEL, | 201 // ElementKind.LABEL, |
| 197 // ElementKind.LIBRARY, | 202 // ElementKind.LIBRARY, |
| 198 if (kind == engine.ElementKind.LOCAL_VARIABLE) return CompletionSuggestionKind
.LOCAL_VARIABLE; | 203 if (kind == |
| 204 engine.ElementKind.LOCAL_VARIABLE) return |
| 205 CompletionSuggestionKind.LOCAL_VARIABLE; |
| 199 if (kind == engine.ElementKind.METHOD) return CompletionSuggestionKind.METHOD; | 206 if (kind == engine.ElementKind.METHOD) return CompletionSuggestionKind.METHOD; |
| 200 // ElementKind.NAME, | 207 // ElementKind.NAME, |
| 201 if (kind == engine.ElementKind.PARAMETER) return CompletionSuggestionKind.PARA
METER; | 208 if (kind == |
| 209 engine.ElementKind.PARAMETER) return CompletionSuggestionKind.PARAMETER; |
| 202 // ElementKind.POLYMER_ATTRIBUTE, | 210 // ElementKind.POLYMER_ATTRIBUTE, |
| 203 // ElementKind.POLYMER_TAG_DART, | 211 // ElementKind.POLYMER_TAG_DART, |
| 204 // ElementKind.POLYMER_TAG_HTML, | 212 // ElementKind.POLYMER_TAG_HTML, |
| 205 // ElementKind.PREFIX, | 213 // ElementKind.PREFIX, |
| 206 if (kind == engine.ElementKind.SETTER) return CompletionSuggestionKind.SETTER; | 214 if (kind == engine.ElementKind.SETTER) return CompletionSuggestionKind.SETTER; |
| 207 if (kind == engine.ElementKind.TOP_LEVEL_VARIABLE) return CompletionSuggestion
Kind.TOP_LEVEL_VARIABLE; | 215 if (kind == |
| 216 engine.ElementKind.TOP_LEVEL_VARIABLE) return |
| 217 CompletionSuggestionKind.TOP_LEVEL_VARIABLE; |
| 208 // ElementKind.TYPE_PARAMETER, | 218 // ElementKind.TYPE_PARAMETER, |
| 209 // ElementKind.UNIVERSE | 219 // ElementKind.UNIVERSE |
| 210 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind'); | 220 throw new ArgumentError('Unknown CompletionSuggestionKind for: $kind'); |
| 211 } | 221 } |
| 212 | 222 |
| 213 /** | 223 /** |
| 214 * Create an ElementKind based on a value from the analyzer engine. Access | 224 * Create an ElementKind based on a value from the analyzer engine. Access |
| 215 * this function via new ElementKind.fromEngine(). | 225 * this function via new ElementKind.fromEngine(). |
| 216 */ | 226 */ |
| 217 ElementKind _elementKindFromEngine(engine.ElementKind kind) { | 227 ElementKind _elementKindFromEngine(engine.ElementKind kind) { |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 423 String className = member.enclosingElement.displayName; | 433 String className = member.enclosingElement.displayName; |
| 424 return new OverriddenMember(element, className); | 434 return new OverriddenMember(element, className); |
| 425 } | 435 } |
| 426 | 436 |
| 427 | 437 |
| 428 /** | 438 /** |
| 429 * Create a [RefactoringFeedback] corresponding the given [kind]. | 439 * Create a [RefactoringFeedback] corresponding the given [kind]. |
| 430 */ | 440 */ |
| 431 RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder, | 441 RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder, |
| 432 String jsonPath, Object json, Map feedbackJson) { | 442 String jsonPath, Object json, Map feedbackJson) { |
| 433 String requestId; | 443 RefactoringKind kind = jsonDecoder.refactoringKind; |
| 434 if (jsonDecoder is ResponseDecoder) { | |
| 435 requestId = jsonDecoder.response.id; | |
| 436 } | |
| 437 RefactoringKind kind = REQUEST_ID_REFACTORING_KINDS.remove(requestId); | |
| 438 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 444 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 439 return new ExtractLocalVariableFeedback.fromJson(jsonDecoder, jsonPath, json
); | 445 return new ExtractLocalVariableFeedback.fromJson( |
| 446 jsonDecoder, |
| 447 jsonPath, |
| 448 json); |
| 440 } | 449 } |
| 441 if (kind == RefactoringKind.EXTRACT_METHOD) { | 450 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 442 return new ExtractMethodFeedback.fromJson(jsonDecoder, jsonPath, json); | 451 return new ExtractMethodFeedback.fromJson(jsonDecoder, jsonPath, json); |
| 443 } | 452 } |
| 444 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { | 453 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { |
| 445 return new InlineLocalVariableFeedback.fromJson(jsonDecoder, jsonPath, json)
; | 454 return new InlineLocalVariableFeedback.fromJson( |
| 455 jsonDecoder, |
| 456 jsonPath, |
| 457 json); |
| 446 } | 458 } |
| 447 if (kind == RefactoringKind.INLINE_METHOD) { | 459 if (kind == RefactoringKind.INLINE_METHOD) { |
| 448 return new InlineMethodFeedback.fromJson(jsonDecoder, jsonPath, json); | 460 return new InlineMethodFeedback.fromJson(jsonDecoder, jsonPath, json); |
| 449 } | 461 } |
| 450 if (kind == RefactoringKind.RENAME) { | 462 if (kind == RefactoringKind.RENAME) { |
| 451 return new RenameFeedback.fromJson(jsonDecoder, jsonPath, json); | 463 return new RenameFeedback.fromJson(jsonDecoder, jsonPath, json); |
| 452 } | 464 } |
| 453 return null; | 465 return null; |
| 454 } | 466 } |
| 455 | 467 |
| 456 | 468 |
| 457 /** | 469 /** |
| 458 * Create a [RefactoringOptions] corresponding the given [kind]. | 470 * Create a [RefactoringOptions] corresponding the given [kind]. |
| 459 */ | 471 */ |
| 460 RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder, | 472 RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder, |
| 461 String jsonPath, Object json, RefactoringKind kind) { | 473 String jsonPath, Object json, RefactoringKind kind) { |
| 462 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 474 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 463 return new ExtractLocalVariableOptions.fromJson(jsonDecoder, jsonPath, json)
; | 475 return new ExtractLocalVariableOptions.fromJson( |
| 476 jsonDecoder, |
| 477 jsonPath, |
| 478 json); |
| 464 } | 479 } |
| 465 if (kind == RefactoringKind.EXTRACT_METHOD) { | 480 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 466 return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json); | 481 return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json); |
| 467 } | 482 } |
| 468 if (kind == RefactoringKind.INLINE_METHOD) { | 483 if (kind == RefactoringKind.INLINE_METHOD) { |
| 469 return new InlineMethodOptions.fromJson(jsonDecoder, jsonPath, json); | 484 return new InlineMethodOptions.fromJson(jsonDecoder, jsonPath, json); |
| 470 } | 485 } |
| 471 if (kind == RefactoringKind.MOVE_FILE) { | 486 if (kind == RefactoringKind.MOVE_FILE) { |
| 472 return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json); | 487 return new MoveFileOptions.fromJson(jsonDecoder, jsonPath, json); |
| 473 } | 488 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 */ | 537 */ |
| 523 dynamic mismatch(String jsonPath, String expected); | 538 dynamic mismatch(String jsonPath, String expected); |
| 524 | 539 |
| 525 /** | 540 /** |
| 526 * Create an exception to throw if the JSON object at [jsonPath] is missing | 541 * Create an exception to throw if the JSON object at [jsonPath] is missing |
| 527 * the key [key]. | 542 * the key [key]. |
| 528 */ | 543 */ |
| 529 dynamic missingKey(String jsonPath, String key); | 544 dynamic missingKey(String jsonPath, String key); |
| 530 | 545 |
| 531 /** | 546 /** |
| 547 * Retrieve the RefactoringKind that should be assumed when decoding |
| 548 * refactoring feedback objects, or null if no refactoring feedback object is |
| 549 * expected to be encountered. |
| 550 */ |
| 551 RefactoringKind get refactoringKind; |
| 552 |
| 553 /** |
| 532 * Decode a JSON object that is expected to be a boolean. The strings "true" | 554 * Decode a JSON object that is expected to be a boolean. The strings "true" |
| 533 * and "false" are also accepted. | 555 * and "false" are also accepted. |
| 534 */ | 556 */ |
| 535 bool _decodeBool(String jsonPath, Object json) { | 557 bool _decodeBool(String jsonPath, Object json) { |
| 536 if (json is bool) { | 558 if (json is bool) { |
| 537 return json; | 559 return json; |
| 538 } else if (json == 'true') { | 560 } else if (json == 'true') { |
| 539 return true; | 561 return true; |
| 540 } else if (json == 'false') { | 562 } else if (json == 'false') { |
| 541 return false; | 563 return false; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 * Initialize a newly created [Notification] to have the given [event] name. | 694 * Initialize a newly created [Notification] to have the given [event] name. |
| 673 * If [_params] is provided, it will be used as the params; otherwise no | 695 * If [_params] is provided, it will be used as the params; otherwise no |
| 674 * params will be used. | 696 * params will be used. |
| 675 */ | 697 */ |
| 676 Notification(this.event, [this._params]); | 698 Notification(this.event, [this._params]); |
| 677 | 699 |
| 678 /** | 700 /** |
| 679 * Initialize a newly created instance based upon the given JSON data | 701 * Initialize a newly created instance based upon the given JSON data |
| 680 */ | 702 */ |
| 681 factory Notification.fromJson(Map<String, Object> json) { | 703 factory Notification.fromJson(Map<String, Object> json) { |
| 682 return new Notification(json[Notification.EVENT], | 704 return new Notification( |
| 705 json[Notification.EVENT], |
| 683 json[Notification.PARAMS]); | 706 json[Notification.PARAMS]); |
| 684 } | 707 } |
| 685 | 708 |
| 686 /** | 709 /** |
| 687 * Return a table representing the structure of the Json object that will be | 710 * Return a table representing the structure of the Json object that will be |
| 688 * sent to the client to represent this response. | 711 * sent to the client to represent this response. |
| 689 */ | 712 */ |
| 690 Map<String, Object> toJson() { | 713 Map<String, Object> toJson() { |
| 691 Map<String, Object> jsonObject = {}; | 714 Map<String, Object> jsonObject = {}; |
| 692 jsonObject[EVENT] = event; | 715 jsonObject[EVENT] = event; |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 812 } | 835 } |
| 813 | 836 |
| 814 @override | 837 @override |
| 815 dynamic missingKey(String jsonPath, String key) { | 838 dynamic missingKey(String jsonPath, String key) { |
| 816 return new RequestFailure( | 839 return new RequestFailure( |
| 817 new Response.invalidParameter( | 840 new Response.invalidParameter( |
| 818 _request, | 841 _request, |
| 819 jsonPath, | 842 jsonPath, |
| 820 'contain key ${JSON.encode(key)}')); | 843 'contain key ${JSON.encode(key)}')); |
| 821 } | 844 } |
| 845 |
| 846 RefactoringKind get refactoringKind { |
| 847 // Refactoring feedback objects should never appear in requests. |
| 848 return null; |
| 849 } |
| 822 } | 850 } |
| 823 | 851 |
| 824 | 852 |
| 825 /** | 853 /** |
| 826 * Instances of the class [RequestFailure] represent an exception that occurred | 854 * Instances of the class [RequestFailure] represent an exception that occurred |
| 827 * during the handling of a request that requires that an error be returned to | 855 * during the handling of a request that requires that an error be returned to |
| 828 * the client. | 856 * the client. |
| 829 */ | 857 */ |
| 830 class RequestFailure implements Exception { | 858 class RequestFailure implements Exception { |
| 831 /** | 859 /** |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 */ | 939 */ |
| 912 factory Response.fromJson(Map<String, Object> json) { | 940 factory Response.fromJson(Map<String, Object> json) { |
| 913 try { | 941 try { |
| 914 Object id = json[Response.ID]; | 942 Object id = json[Response.ID]; |
| 915 if (id is! String) { | 943 if (id is! String) { |
| 916 return null; | 944 return null; |
| 917 } | 945 } |
| 918 Object error = json[Response.ERROR]; | 946 Object error = json[Response.ERROR]; |
| 919 RequestError decodedError; | 947 RequestError decodedError; |
| 920 if (error is Map) { | 948 if (error is Map) { |
| 921 decodedError = new RequestError.fromJson(new ResponseDecoder(null), | 949 decodedError = |
| 922 '.error', error); | 950 new RequestError.fromJson(new ResponseDecoder(null), '.error', error
); |
| 923 } | 951 } |
| 924 Object result = json[Response.RESULT]; | 952 Object result = json[Response.RESULT]; |
| 925 Map<String, Object> decodedResult; | 953 Map<String, Object> decodedResult; |
| 926 if (result is Map) { | 954 if (result is Map) { |
| 927 decodedResult = result; | 955 decodedResult = result; |
| 928 } | 956 } |
| 929 return new Response(id, error: decodedError, | 957 return new Response(id, error: decodedError, result: decodedResult); |
| 930 result: decodedResult); | |
| 931 } catch (exception) { | 958 } catch (exception) { |
| 932 return null; | 959 return null; |
| 933 } | 960 } |
| 934 } | 961 } |
| 935 | 962 |
| 936 /** | 963 /** |
| 937 * Initialize a newly created instance to represent the | 964 * Initialize a newly created instance to represent the |
| 938 * GET_ERRORS_INVALID_FILE error condition. | 965 * GET_ERRORS_INVALID_FILE error condition. |
| 939 */ | 966 */ |
| 940 Response.getErrorsInvalidFile(Request request) | 967 Response.getErrorsInvalidFile(Request request) |
| 941 : this( | 968 : this( |
| 942 request.id, | 969 request.id, |
| 943 error: new RequestError(RequestErrorCode.GET_ERRORS_INVALID_FILE, | 970 error: new RequestError( |
| 944 'Error during `analysis.getErrors`: invalid file.')); | 971 RequestErrorCode.GET_ERRORS_INVALID_FILE, |
| 972 'Error during `analysis.getErrors`: invalid file.')); |
| 945 | 973 |
| 946 /** | 974 /** |
| 947 * Initialize a newly created instance to represent an error condition caused | 975 * Initialize a newly created instance to represent an error condition caused |
| 948 * by a [request] that had invalid parameter. [path] is the path to the | 976 * by a [request] that had invalid parameter. [path] is the path to the |
| 949 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the | 977 * invalid parameter, in Javascript notation (e.g. "foo.bar" means that the |
| 950 * parameter "foo" contained a key "bar" whose value was the wrong type). | 978 * parameter "foo" contained a key "bar" whose value was the wrong type). |
| 951 * [expectation] is a description of the type of data that was expected. | 979 * [expectation] is a description of the type of data that was expected. |
| 952 */ | 980 */ |
| 953 Response.invalidParameter(Request request, String path, String expectation) | 981 Response.invalidParameter(Request request, String path, String expectation) |
| 954 : this(request.id, error: new RequestError(RequestErrorCode.INVALID_PARAME
TER, | 982 : this( |
| 955 "Expected parameter $path to $expectation")); | 983 request.id, |
| 984 error: new RequestError( |
| 985 RequestErrorCode.INVALID_PARAMETER, |
| 986 "Expected parameter $path to $expectation")); |
| 956 | 987 |
| 957 /** | 988 /** |
| 958 * Initialize a newly created instance to represent an error condition caused | 989 * Initialize a newly created instance to represent an error condition caused |
| 959 * by a malformed request. | 990 * by a malformed request. |
| 960 */ | 991 */ |
| 961 Response.invalidRequestFormat() | 992 Response.invalidRequestFormat() |
| 962 : this('', error: new RequestError(RequestErrorCode.INVALID_REQUEST, 'Invali
d request')); | 993 : this( |
| 994 '', |
| 995 error: new RequestError(RequestErrorCode.INVALID_REQUEST, 'Invalid req
uest')); |
| 963 | 996 |
| 964 /** | 997 /** |
| 965 * Initialize a newly created instance to represent the | 998 * Initialize a newly created instance to represent the |
| 966 * SORT_MEMBERS_INVALID_FILE error condition. | 999 * SORT_MEMBERS_INVALID_FILE error condition. |
| 967 */ | 1000 */ |
| 968 Response.sortMembersInvalidFile(Request request) | 1001 Response.sortMembersInvalidFile(Request request) |
| 969 : this( | 1002 : this( |
| 970 request.id, | 1003 request.id, |
| 971 error: new RequestError(RequestErrorCode.SORT_MEMBERS_INVALID_FILE, | 1004 error: new RequestError( |
| 972 'Error during `edit.sortMembers`: invalid file.')); | 1005 RequestErrorCode.SORT_MEMBERS_INVALID_FILE, |
| 1006 'Error during `edit.sortMembers`: invalid file.')); |
| 973 | 1007 |
| 974 /** | 1008 /** |
| 975 * Initialize a newly created instance to represent the | 1009 * Initialize a newly created instance to represent the |
| 976 * SORT_MEMBERS_PARSE_ERRORS error condition. | 1010 * SORT_MEMBERS_PARSE_ERRORS error condition. |
| 977 */ | 1011 */ |
| 978 Response.sortMembersParseErrors(Request request, int numErrors) | 1012 Response.sortMembersParseErrors(Request request, int numErrors) |
| 979 : this( | 1013 : this( |
| 980 request.id, | 1014 request.id, |
| 981 error: new RequestError(RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS, | 1015 error: new RequestError( |
| 982 'Error during `edit.sortMembers`: file has $numErrors scan/parse err
ors.')); | 1016 RequestErrorCode.SORT_MEMBERS_PARSE_ERRORS, |
| 1017 'Error during `edit.sortMembers`: file has $numErrors scan/parse e
rrors.')); |
| 983 | 1018 |
| 984 /** | 1019 /** |
| 985 * Initialize a newly created instance to represent an error condition caused | 1020 * Initialize a newly created instance to represent an error condition caused |
| 986 * by a `analysis.setPriorityFiles` [request] that includes one or more files | 1021 * by a `analysis.setPriorityFiles` [request] that includes one or more files |
| 987 * that are not being analyzed. | 1022 * that are not being analyzed. |
| 988 */ | 1023 */ |
| 989 Response.unanalyzedPriorityFiles(Request request, String fileNames) | 1024 Response.unanalyzedPriorityFiles(Request request, String fileNames) |
| 990 : this(request.id, error: new RequestError(RequestErrorCode.UNANALYZED_PRIOR
ITY_FILES, "Unanalyzed files cannot be a priority: '$fileNames'")); | 1025 : this( |
| 1026 request.id, |
| 1027 error: new RequestError( |
| 1028 RequestErrorCode.UNANALYZED_PRIORITY_FILES, |
| 1029 "Unanalyzed files cannot be a priority: '$fileNames'")); |
| 991 | 1030 |
| 992 /** | 1031 /** |
| 993 * Initialize a newly created instance to represent an error condition caused | 1032 * Initialize a newly created instance to represent an error condition caused |
| 994 * by a [request] that cannot be handled by any known handlers. | 1033 * by a [request] that cannot be handled by any known handlers. |
| 995 */ | 1034 */ |
| 996 Response.unknownRequest(Request request) | 1035 Response.unknownRequest(Request request) |
| 997 : this(request.id, error: new RequestError(RequestErrorCode.UNKNOWN_REQUEST,
'Unknown request')); | 1036 : this( |
| 1037 request.id, |
| 1038 error: new RequestError(RequestErrorCode.UNKNOWN_REQUEST, 'Unknown req
uest')); |
| 998 | 1039 |
| 999 Response.unsupportedFeature(String requestId, String message) | 1040 Response.unsupportedFeature(String requestId, String message) |
| 1000 : this(requestId, error: new RequestError(RequestErrorCode.UNSUPPORTED_FEATU
RE, message)); | 1041 : this( |
| 1042 requestId, |
| 1043 error: new RequestError(RequestErrorCode.UNSUPPORTED_FEATURE, message)
); |
| 1001 | 1044 |
| 1002 /** | 1045 /** |
| 1003 * Return a table representing the structure of the Json object that will be | 1046 * Return a table representing the structure of the Json object that will be |
| 1004 * sent to the client to represent this response. | 1047 * sent to the client to represent this response. |
| 1005 */ | 1048 */ |
| 1006 Map<String, Object> toJson() { | 1049 Map<String, Object> toJson() { |
| 1007 Map<String, Object> jsonObject = new HashMap<String, Object>(); | 1050 Map<String, Object> jsonObject = new HashMap<String, Object>(); |
| 1008 jsonObject[ID] = id; | 1051 jsonObject[ID] = id; |
| 1009 if (error != null) { | 1052 if (error != null) { |
| 1010 jsonObject[ERROR] = error.toJson(); | 1053 jsonObject[ERROR] = error.toJson(); |
| 1011 } | 1054 } |
| 1012 if (_result != null) { | 1055 if (_result != null) { |
| 1013 jsonObject[RESULT] = _result; | 1056 jsonObject[RESULT] = _result; |
| 1014 } | 1057 } |
| 1015 return jsonObject; | 1058 return jsonObject; |
| 1016 } | 1059 } |
| 1017 } | 1060 } |
| 1018 | 1061 |
| 1019 /** | 1062 /** |
| 1020 * JsonDecoder for decoding responses from the server. This is intended to be | 1063 * JsonDecoder for decoding responses from the server. This is intended to be |
| 1021 * used only for testing. Errors are reported using bare [Exception] objects. | 1064 * used only for testing. Errors are reported using bare [Exception] objects. |
| 1022 */ | 1065 */ |
| 1023 class ResponseDecoder extends JsonDecoder { | 1066 class ResponseDecoder extends JsonDecoder { |
| 1024 final Response response; | 1067 final RefactoringKind refactoringKind; |
| 1025 | 1068 |
| 1026 ResponseDecoder(this.response); | 1069 ResponseDecoder(this.refactoringKind); |
| 1027 | 1070 |
| 1028 @override | 1071 @override |
| 1029 dynamic mismatch(String jsonPath, String expected) { | 1072 dynamic mismatch(String jsonPath, String expected) { |
| 1030 return new Exception('Expected $expected at $jsonPath'); | 1073 return new Exception('Expected $expected at $jsonPath'); |
| 1031 } | 1074 } |
| 1032 | 1075 |
| 1033 @override | 1076 @override |
| 1034 dynamic missingKey(String jsonPath, String key) { | 1077 dynamic missingKey(String jsonPath, String key) { |
| 1035 return new Exception('Missing key $key at $jsonPath'); | 1078 return new Exception('Missing key $key at $jsonPath'); |
| 1036 } | 1079 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1053 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 1096 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 1054 hash = hash ^ (hash >> 11); | 1097 hash = hash ^ (hash >> 11); |
| 1055 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 1098 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 1056 } | 1099 } |
| 1057 | 1100 |
| 1058 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 1101 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 1059 | 1102 |
| 1060 static int hash4(a, b, c, d) => | 1103 static int hash4(a, b, c, d) => |
| 1061 finish(combine(combine(combine(combine(0, a), b), c), d)); | 1104 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 1062 } | 1105 } |
| OLD | NEW |