OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 import 'package:analysis_server/protocol/protocol_generated.dart' as server; | 5 import 'package:analysis_server/protocol/protocol_generated.dart' as server; |
6 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; | 6 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server; |
7 import 'package:analyzer_plugin/protocol/protocol_common.dart' as plugin; | 7 import 'package:analyzer_plugin/protocol/protocol_common.dart'; |
8 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; | 8 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin; |
9 | 9 |
10 /** | 10 /** |
11 * An object used to convert between similar objects defined by both the plugin | 11 * An object used to convert between similar objects defined by both the plugin |
12 * protocol and the server protocol. | 12 * protocol and the server protocol. |
13 */ | 13 */ |
14 class ResultConverter { | 14 class ResultConverter { |
15 /** | 15 /** |
16 * The decoder used to decode Json representations of server objects. | 16 * The decoder used to decode Json representations of server objects. |
17 */ | 17 */ |
18 static final server.ResponseDecoder decoder = | 18 static final server.ResponseDecoder decoder = |
19 new server.ResponseDecoder(null); | 19 new server.ResponseDecoder(null); |
20 | 20 |
21 server.AnalysisError convertAnalysisError(plugin.AnalysisError error) { | |
22 return new server.AnalysisError.fromJson(decoder, '', error.toJson()); | |
23 } | |
24 | |
25 server.AnalysisErrorFixes convertAnalysisErrorFixes( | 21 server.AnalysisErrorFixes convertAnalysisErrorFixes( |
26 plugin.AnalysisErrorFixes fixes) { | 22 plugin.AnalysisErrorFixes fixes) { |
27 List<server.SourceChange> changes = fixes.fixes | 23 List<SourceChange> changes = fixes.fixes |
28 .map((plugin.PrioritizedSourceChange change) => | 24 .map((plugin.PrioritizedSourceChange change) => |
29 convertPrioritizedSourceChange(change)) | 25 convertPrioritizedSourceChange(change)) |
30 .toList(); | 26 .toList(); |
31 return new server.AnalysisErrorFixes(convertAnalysisError(fixes.error), | 27 return new server.AnalysisErrorFixes(fixes.error, fixes: changes); |
32 fixes: changes); | |
33 } | 28 } |
34 | 29 |
35 server.AnalysisNavigationParams convertAnalysisNavigationParams( | 30 server.AnalysisNavigationParams convertAnalysisNavigationParams( |
36 plugin.AnalysisNavigationParams params) { | 31 plugin.AnalysisNavigationParams params) { |
37 return new server.AnalysisNavigationParams.fromJson( | 32 return new server.AnalysisNavigationParams.fromJson( |
38 decoder, '', params.toJson()); | 33 decoder, '', params.toJson()); |
39 } | 34 } |
40 | 35 |
41 server.CompletionSuggestion convertCompletionSuggestion( | 36 server.EditGetRefactoringResult convertEditGetRefactoringResult( |
42 plugin.CompletionSuggestion suggestion) { | 37 RefactoringKind kind, plugin.EditGetRefactoringResult result) { |
43 return new server.CompletionSuggestion.fromJson( | 38 return new server.EditGetRefactoringResult.fromJson( |
44 decoder, '', suggestion.toJson()); | 39 new server.ResponseDecoder(kind), '', result.toJson()); |
45 } | 40 } |
46 | 41 |
47 server.EditGetRefactoringResult convertEditGetRefactoringResult( | 42 SourceChange convertPrioritizedSourceChange( |
48 plugin.RefactoringKind kind, plugin.EditGetRefactoringResult result) { | |
49 return new server.EditGetRefactoringResult.fromJson( | |
50 new server.ResponseDecoder(convertRefactoringKind(kind)), | |
51 '', | |
52 result.toJson()); | |
53 } | |
54 | |
55 server.FoldingRegion convertFoldingRegion(plugin.FoldingRegion region) { | |
56 return new server.FoldingRegion.fromJson(decoder, '', region.toJson()); | |
57 } | |
58 | |
59 server.HighlightRegion convertHighlightRegion(plugin.HighlightRegion region) { | |
60 return new server.HighlightRegion.fromJson(decoder, '', region.toJson()); | |
61 } | |
62 | |
63 server.Occurrences convertOccurrences(plugin.Occurrences occurrences) { | |
64 return new server.Occurrences.fromJson(decoder, '', occurrences.toJson()); | |
65 } | |
66 | |
67 server.Outline convertOutline(plugin.Outline outline) { | |
68 return new server.Outline.fromJson(decoder, '', outline.toJson()); | |
69 } | |
70 | |
71 server.SourceChange convertPrioritizedSourceChange( | |
72 plugin.PrioritizedSourceChange change) { | 43 plugin.PrioritizedSourceChange change) { |
73 return convertSourceChange(change.change); | 44 return change.change; |
74 } | |
75 | |
76 server.RefactoringFeedback convertRefactoringFeedback( | |
77 plugin.RefactoringKind kind, plugin.RefactoringFeedback feedback) { | |
78 return new server.RefactoringFeedback.fromJson( | |
79 new server.ResponseDecoder(convertRefactoringKind(kind)), | |
80 '', | |
81 feedback.toJson(), | |
82 null); | |
83 } | |
84 | |
85 server.RefactoringKind convertRefactoringKind( | |
86 plugin.RefactoringKind feedback) { | |
87 return new server.RefactoringKind.fromJson(decoder, '', feedback.toJson()); | |
88 } | |
89 | |
90 server.SourceChange convertSourceChange(plugin.SourceChange change) { | |
91 return new server.SourceChange.fromJson(decoder, '', change.toJson()); | |
92 } | 45 } |
93 } | 46 } |
OLD | NEW |