Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: pkg/analysis_server/lib/src/plugin/result_converter.dart

Issue 2689903002: Add conversion routines from the plugin API to the server API (Closed)
Patch Set: Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 import 'package:analysis_server/plugin/protocol/protocol.dart' as server;
6 import 'package:analysis_server/src/protocol/protocol_internal.dart' as server;
7 import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
8
9 /**
10 * An object used to convert between similar objects defined by both the plugin
11 * protocol and the server protocol.
12 */
13 class ResultConverter {
14 /**
15 * The decoder used to decode Json representations of server objects.
16 */
17 static final server.ResponseDecoder decoder =
18 new server.ResponseDecoder(null);
19
20 server.AnalysisError convertAnalysisError(plugin.AnalysisError error) {
21 return new server.AnalysisError.fromJson(decoder, '', error.toJson());
22 }
23
24 server.AnalysisErrorFixes convertAnalysisErrorFixes(
25 plugin.AnalysisErrorFixes fixes) {
26 List<server.SourceChange> changes = fixes.fixes
27 .map((plugin.PrioritizedSourceChange change) =>
28 convertPrioritizedSourceChange(change))
29 .toList();
30 return new server.AnalysisErrorFixes(convertAnalysisError(fixes.error),
31 fixes: changes);
32 }
33
34 server.AnalysisNavigationParams convertAnalysisNavigationParams(
35 plugin.AnalysisNavigationParams params) {
36 return new server.AnalysisNavigationParams.fromJson(
37 decoder, '', params.toJson());
38 }
39
40 server.CompletionSuggestion convertCompletionSuggestion(
41 plugin.CompletionSuggestion suggestion) {
42 return new server.CompletionSuggestion.fromJson(
43 decoder, '', suggestion.toJson());
44 }
45
46 server.EditGetRefactoringResult convertEditGetRefactoringResult(
47 plugin.RefactoringKind kind, plugin.EditGetRefactoringResult result) {
48 return new server.EditGetRefactoringResult.fromJson(
49 new server.ResponseDecoder(convertRefactoringKind(kind)),
50 '',
51 result.toJson());
52 }
53
54 server.FoldingRegion convertFoldingRegion(plugin.FoldingRegion region) {
55 return new server.FoldingRegion.fromJson(decoder, '', region.toJson());
56 }
57
58 server.HighlightRegion convertHighlightRegion(plugin.HighlightRegion region) {
59 return new server.HighlightRegion.fromJson(decoder, '', region.toJson());
60 }
61
62 server.Occurrences convertOccurrences(plugin.Occurrences occurrences) {
63 return new server.Occurrences.fromJson(decoder, '', occurrences.toJson());
64 }
65
66 server.Outline convertOutline(plugin.Outline outline) {
67 return new server.Outline.fromJson(decoder, '', outline.toJson());
68 }
69
70 server.SourceChange convertPrioritizedSourceChange(
71 plugin.PrioritizedSourceChange change) {
72 return convertSourceChange(change.change);
73 }
74
75 server.RefactoringFeedback convertRefactoringFeedback(
76 plugin.RefactoringKind kind, plugin.RefactoringFeedback feedback) {
77 return new server.RefactoringFeedback.fromJson(
78 new server.ResponseDecoder(convertRefactoringKind(kind)),
79 '',
80 feedback.toJson(),
81 null);
82 }
83
84 server.RefactoringKind convertRefactoringKind(
85 plugin.RefactoringKind feedback) {
86 return new server.RefactoringKind.fromJson(decoder, '', feedback.toJson());
87 }
88
89 server.SourceChange convertSourceChange(plugin.SourceChange change) {
90 return new server.SourceChange.fromJson(decoder, '', change.toJson());
91 }
92 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698