| 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 |
| 11 elementFromEngine; | 11 elementFromEngine; |
| 12 import 'package:analysis_server/src/search/search_result.dart' show | 12 import 'package:analysis_server/src/search/search_result.dart' show |
| 13 searchResultFromMatch; | 13 searchResultFromMatch; |
| 14 import 'package:analysis_server/src/services/correction/fix.dart' show Fix; | 14 import 'package:analysis_server/src/services/correction/fix.dart' show Fix; |
| 15 import 'package:analysis_server/src/services/json.dart'; | 15 import 'package:analysis_server/src/services/json.dart'; |
| 16 import 'package:analysis_server/src/services/search/search_engine.dart' as | 16 import 'package:analysis_server/src/services/search/search_engine.dart' as |
| 17 engine; | 17 engine; |
| 18 import 'package:analyzer/src/generated/ast.dart' as engine; | 18 import 'package:analyzer/src/generated/ast.dart' as engine; |
| 19 import 'package:analyzer/src/generated/element.dart' as engine; | 19 import 'package:analyzer/src/generated/element.dart' as engine; |
| 20 import 'package:analyzer/src/generated/engine.dart' as engine; | 20 import 'package:analyzer/src/generated/engine.dart' as engine; |
| 21 import 'package:analyzer/src/generated/error.dart' as engine; | 21 import 'package:analyzer/src/generated/error.dart' as engine; |
| 22 import 'package:analyzer/src/generated/source.dart' as engine; | 22 import 'package:analyzer/src/generated/source.dart' as engine; |
| 23 | 23 |
| 24 part 'generated_protocol.dart'; | 24 part 'generated_protocol.dart'; |
| 25 | 25 |
| 26 |
| 27 final Map<String, RefactoringKind> REQUEST_ID_REFACTORING_KINDS = |
| 28 new HashMap<String, RefactoringKind>(); |
| 29 |
| 26 /** | 30 /** |
| 27 * Translate the input [map], applying [keyCallback] to all its keys, and | 31 * Translate the input [map], applying [keyCallback] to all its keys, and |
| 28 * [valueCallback] to all its values. | 32 * [valueCallback] to all its values. |
| 29 */ | 33 */ |
| 30 mapMap(Map map, {dynamic keyCallback(key), dynamic valueCallback(value)}) { | 34 mapMap(Map map, {dynamic keyCallback(key), dynamic valueCallback(value)}) { |
| 31 Map result = {}; | 35 Map result = {}; |
| 32 map.forEach((key, value) { | 36 map.forEach((key, value) { |
| 33 if (keyCallback != null) { | 37 if (keyCallback != null) { |
| 34 key = keyCallback(key); | 38 key = keyCallback(key); |
| 35 } | 39 } |
| (...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 * Create an OverriddenMember based on an element from the analyzer engine. | 393 * Create an OverriddenMember based on an element from the analyzer engine. |
| 390 */ | 394 */ |
| 391 OverriddenMember _overriddenMemberFromEngine(engine.Element member) { | 395 OverriddenMember _overriddenMemberFromEngine(engine.Element member) { |
| 392 Element element = elementFromEngine(member); | 396 Element element = elementFromEngine(member); |
| 393 String className = member.enclosingElement.displayName; | 397 String className = member.enclosingElement.displayName; |
| 394 return new OverriddenMember(element, className); | 398 return new OverriddenMember(element, className); |
| 395 } | 399 } |
| 396 | 400 |
| 397 | 401 |
| 398 /** | 402 /** |
| 403 * Create a [RefactoringFeedback] corresponding the given [kind]. |
| 404 */ |
| 405 RefactoringFeedback _refactoringFeedbackFromJson(JsonDecoder jsonDecoder, |
| 406 String jsonPath, Object json, Map feedbackJson) { |
| 407 String requestId; |
| 408 if (jsonDecoder is ResponseDecoder) { |
| 409 requestId = jsonDecoder.response.id; |
| 410 } |
| 411 RefactoringKind kind = REQUEST_ID_REFACTORING_KINDS[requestId]; |
| 412 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 413 return new ExtractLocalVariableFeedback.fromJson(jsonDecoder, jsonPath, json
); |
| 414 } |
| 415 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 416 return new ExtractMethodFeedback.fromJson(jsonDecoder, jsonPath, json); |
| 417 } |
| 418 if (kind == RefactoringKind.RENAME) { |
| 419 return new RenameFeedback.fromJson(jsonDecoder, jsonPath, json); |
| 420 } |
| 421 return null; |
| 422 } |
| 423 |
| 424 |
| 425 /** |
| 399 * Create a [RefactoringOptions] corresponding the given [kind]. | 426 * Create a [RefactoringOptions] corresponding the given [kind]. |
| 400 */ | 427 */ |
| 401 RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder, | 428 RefactoringOptions _refactoringOptionsFromJson(JsonDecoder jsonDecoder, |
| 402 String jsonPath, Object json, RefactoringKind kind) { | 429 String jsonPath, Object json, RefactoringKind kind) { |
| 403 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { | 430 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { |
| 404 return new ExtractLocalVariableOptions.fromJson(jsonDecoder, jsonPath, json)
; | 431 return new ExtractLocalVariableOptions.fromJson(jsonDecoder, jsonPath, json)
; |
| 405 } | 432 } |
| 406 if (kind == RefactoringKind.EXTRACT_METHOD) { | 433 if (kind == RefactoringKind.EXTRACT_METHOD) { |
| 407 return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json); | 434 return new ExtractMethodOptions.fromJson(jsonDecoder, jsonPath, json); |
| 408 } | 435 } |
| (...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 849 */ | 876 */ |
| 850 factory Response.fromJson(Map<String, Object> json) { | 877 factory Response.fromJson(Map<String, Object> json) { |
| 851 try { | 878 try { |
| 852 Object id = json[Response.ID]; | 879 Object id = json[Response.ID]; |
| 853 if (id is! String) { | 880 if (id is! String) { |
| 854 return null; | 881 return null; |
| 855 } | 882 } |
| 856 Object error = json[Response.ERROR]; | 883 Object error = json[Response.ERROR]; |
| 857 RequestError decodedError; | 884 RequestError decodedError; |
| 858 if (error is Map) { | 885 if (error is Map) { |
| 859 decodedError = new RequestError.fromJson(new ResponseDecoder(), | 886 decodedError = new RequestError.fromJson(new ResponseDecoder(null), |
| 860 '.error', error); | 887 '.error', error); |
| 861 } | 888 } |
| 862 Object result = json[Response.RESULT]; | 889 Object result = json[Response.RESULT]; |
| 863 Map<String, Object> decodedResult; | 890 Map<String, Object> decodedResult; |
| 864 if (result is Map) { | 891 if (result is Map) { |
| 865 decodedResult = result; | 892 decodedResult = result; |
| 866 } | 893 } |
| 867 return new Response(id, error: decodedError, | 894 return new Response(id, error: decodedError, |
| 868 result: decodedResult); | 895 result: decodedResult); |
| 869 } catch (exception) { | 896 } catch (exception) { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 } | 959 } |
| 933 return jsonObject; | 960 return jsonObject; |
| 934 } | 961 } |
| 935 } | 962 } |
| 936 | 963 |
| 937 /** | 964 /** |
| 938 * JsonDecoder for decoding responses from the server. This is intended to be | 965 * JsonDecoder for decoding responses from the server. This is intended to be |
| 939 * used only for testing. Errors are reported using bare [Exception] objects. | 966 * used only for testing. Errors are reported using bare [Exception] objects. |
| 940 */ | 967 */ |
| 941 class ResponseDecoder extends JsonDecoder { | 968 class ResponseDecoder extends JsonDecoder { |
| 969 final Response response; |
| 970 |
| 971 ResponseDecoder(this.response); |
| 972 |
| 942 @override | 973 @override |
| 943 dynamic mismatch(String jsonPath, String expected) { | 974 dynamic mismatch(String jsonPath, String expected) { |
| 944 return new Exception('Expected $expected at $jsonPath'); | 975 return new Exception('Expected $expected at $jsonPath'); |
| 945 } | 976 } |
| 946 | 977 |
| 947 @override | 978 @override |
| 948 dynamic missingKey(String jsonPath, String key) { | 979 dynamic missingKey(String jsonPath, String key) { |
| 949 return new Exception('Missing key $key at $jsonPath'); | 980 return new Exception('Missing key $key at $jsonPath'); |
| 950 } | 981 } |
| 951 } | 982 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 967 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); | 998 hash = 0x1fffffff & (hash + ((0x03ffffff & hash) << 3)); |
| 968 hash = hash ^ (hash >> 11); | 999 hash = hash ^ (hash >> 11); |
| 969 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); | 1000 return 0x1fffffff & (hash + ((0x00003fff & hash) << 15)); |
| 970 } | 1001 } |
| 971 | 1002 |
| 972 static int hash2(a, b) => finish(combine(combine(0, a), b)); | 1003 static int hash2(a, b) => finish(combine(combine(0, a), b)); |
| 973 | 1004 |
| 974 static int hash4(a, b, c, d) => | 1005 static int hash4(a, b, c, d) => |
| 975 finish(combine(combine(combine(combine(0, a), b), c), d)); | 1006 finish(combine(combine(combine(combine(0, a), b), c), d)); |
| 976 } | 1007 } |
| OLD | NEW |