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

Side by Side Diff: pkg/analysis_server/lib/src/domain_analysis.dart

Issue 492563002: Make more use of generated classes in analysis server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
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 domain.analysis; 5 library domain.analysis;
6 6
7 import 'dart:collection';
8
9 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/computer/computer_hover.dart'; 8 import 'package:analysis_server/src/computer/computer_hover.dart';
11 import 'package:analysis_server/src/computer/error.dart'; 9 import 'package:analysis_server/src/computer/error.dart';
12 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
13 import 'package:analysis_server/src/protocol.dart'; 11 import 'package:analysis_server/src/protocol.dart';
14 import 'package:analysis_server/src/protocol2.dart'; 12 import 'package:analysis_server/src/protocol2.dart';
15 import 'package:analysis_server/src/services/correction/change.dart';
16 import 'package:analyzer/src/generated/ast.dart'; 13 import 'package:analyzer/src/generated/ast.dart';
17 import 'package:analyzer/src/generated/engine.dart' as engine; 14 import 'package:analyzer/src/generated/engine.dart' as engine;
18 15
19 16
20 /** 17 /**
21 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler] 18 * Instances of the class [AnalysisDomainHandler] implement a [RequestHandler]
22 * that handles requests in the `analysis` domain. 19 * that handles requests in the `analysis` domain.
23 */ 20 */
24 class AnalysisDomainHandler implements RequestHandler { 21 class AnalysisDomainHandler implements RequestHandler {
25 /** 22 /**
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 }); 55 });
59 // delay response 56 // delay response
60 return Response.DELAYED_RESPONSE; 57 return Response.DELAYED_RESPONSE;
61 } 58 }
62 59
63 /** 60 /**
64 * Implement the `analysis.getHover` request. 61 * Implement the `analysis.getHover` request.
65 */ 62 */
66 Response getHover(Request request) { 63 Response getHover(Request request) {
67 // prepare parameters 64 // prepare parameters
68 String file = request.getRequiredParameter(FILE).asString(); 65 var params = new AnalysisGetHoverParams.fromRequest(request);
69 int offset = request.getRequiredParameter(OFFSET).asInt();
70 // prepare hovers 66 // prepare hovers
71 List<Hover> hovers = <Hover>[]; 67 List<Hover> hovers = <Hover>[];
72 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 68 List<CompilationUnit> units =
69 server.getResolvedCompilationUnits(params.file);
73 for (CompilationUnit unit in units) { 70 for (CompilationUnit unit in units) {
74 Hover hoverInformation = 71 Hover hoverInformation =
75 new DartUnitHoverComputer(unit, offset).compute(); 72 new DartUnitHoverComputer(unit, params.offset).compute();
76 if (hoverInformation != null) { 73 if (hoverInformation != null) {
77 hovers.add(hoverInformation); 74 hovers.add(hoverInformation);
78 } 75 }
79 } 76 }
80 // send response 77 // send response
81 Response response = new Response(request.id); 78 Response response = new Response(request.id);
82 response.setResult(HOVERS, hovers); 79 response.setResult(HOVERS, hovers);
83 return response; 80 return response;
84 } 81 }
85 82
(...skipping 19 matching lines...) Expand all
105 } on RequestFailure catch (exception) { 102 } on RequestFailure catch (exception) {
106 return exception.response; 103 return exception.response;
107 } 104 }
108 return null; 105 return null;
109 } 106 }
110 107
111 /** 108 /**
112 * Implement the 'analysis.setAnalysisRoots' request. 109 * Implement the 'analysis.setAnalysisRoots' request.
113 */ 110 */
114 Response setAnalysisRoots(Request request) { 111 Response setAnalysisRoots(Request request) {
115 // included 112 var params = new AnalysisSetAnalysisRootsParams.fromRequest(request);
116 RequestDatum includedDatum = request.getRequiredParameter(INCLUDED);
117 List<String> includedPaths = includedDatum.asStringList();
118 // excluded
119 RequestDatum excludedDatum = request.getRequiredParameter(EXCLUDED);
120 List<String> excludedPaths = excludedDatum.asStringList();
121 // continue in server 113 // continue in server
122 server.setAnalysisRoots(request.id, includedPaths, excludedPaths); 114 server.setAnalysisRoots(request.id, params.included, params.excluded);
123 return new Response(request.id); 115 return new Response(request.id);
124 } 116 }
125 117
126 /** 118 /**
127 * Implement the 'analysis.setPriorityFiles' request. 119 * Implement the 'analysis.setPriorityFiles' request.
128 */ 120 */
129 Response setPriorityFiles(Request request) { 121 Response setPriorityFiles(Request request) {
130 // files 122 var params = new AnalysisSetPriorityFilesParams.fromRequest(request);
131 RequestDatum filesDatum = request.getRequiredParameter(FILES); 123 server.setPriorityFiles(request, params.files);
132 List<String> files = filesDatum.asStringList();
133 server.setPriorityFiles(request, files);
134 return new Response(request.id); 124 return new Response(request.id);
135 } 125 }
136 126
137 /** 127 /**
138 * Implement the 'analysis.setSubscriptions' request. 128 * Implement the 'analysis.setSubscriptions' request.
139 */ 129 */
140 Response setSubscriptions(Request request) { 130 Response setSubscriptions(Request request) {
131 var params = new AnalysisSetSubscriptionsParams.fromRequest(request);
141 // parse subscriptions 132 // parse subscriptions
142 Map<AnalysisService, Set<String>> subMap; 133 Map<AnalysisService, Set<String>> subMap =
143 { 134 mapMap(params.subscriptions, valueCallback:
144 Map<AnalysisService, List<String>> subscriptions = 135 (List<String> subscriptions) => subscriptions.toSet());
145 new AnalysisSetSubscriptionsParams.fromRequest(request).subscriptions;
146 subMap = new HashMap<AnalysisService, Set<String>>();
147 subscriptions.forEach((AnalysisService service, List<String> paths) {
148 subMap[service] = new HashSet.from(paths);
149 });
150 }
151 server.setAnalysisSubscriptions(subMap); 136 server.setAnalysisSubscriptions(subMap);
152 return new Response(request.id); 137 return new Response(request.id);
153 } 138 }
154 139
155 /** 140 /**
156 * Implement the 'analysis.updateContent' request. 141 * Implement the 'analysis.updateContent' request.
157 */ 142 */
158 Response updateContent(Request request) { 143 Response updateContent(Request request) {
159 var changes = new HashMap<String, ContentChange>(); 144 var params = new AnalysisUpdateContentParams.fromRequest(request);
160 RequestDatum filesDatum = request.getRequiredParameter(FILES); 145 server.updateContent(params.files);
161 for (String file in filesDatum.keys) {
162 RequestDatum changeDatum = filesDatum[file];
163 ContentChange change = new ContentChange();
164 change.type = changeDatum[TYPE].asString();
165 switch (change.type) {
166 case ADD:
167 change.content = changeDatum[CONTENT].asString();
168 break;
169 case CHANGE:
170 change.changes = changeDatum[EDITS].asList((RequestDatum item) {
171 int offset = item[OFFSET].asInt();
172 int length = item[LENGTH].asInt();
173 String replacement = item[REPLACEMENT].asString();
174 return new Edit(offset, length, replacement);
175 });
176 break;
177 case REMOVE:
178 break;
179 default:
180 return new Response.invalidParameter(
181 request,
182 changeDatum[TYPE].path,
183 'be one of "add", "change", or "remove"');
184 }
185 changes[file] = change;
186 }
187 server.updateContent(changes);
188 return new Response(request.id); 146 return new Response(request.id);
189 } 147 }
190 148
191 /** 149 /**
192 * Implement the 'analysis.updateOptions' request. 150 * Implement the 'analysis.updateOptions' request.
193 */ 151 */
194 Response updateOptions(Request request) { 152 Response updateOptions(Request request) {
195 // options 153 // options
196 var params = new AnalysisUpdateOptionsParams.fromRequest(request); 154 var params = new AnalysisUpdateOptionsParams.fromRequest(request);
197 AnalysisOptions newOptions = params.options; 155 AnalysisOptions newOptions = params.options;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 } 187 }
230 if (newOptions.generateHints != null) { 188 if (newOptions.generateHints != null) {
231 updaters.add((engine.AnalysisOptionsImpl options) { 189 updaters.add((engine.AnalysisOptionsImpl options) {
232 options.hint = newOptions.generateHints; 190 options.hint = newOptions.generateHints;
233 }); 191 });
234 } 192 }
235 server.updateOptions(updaters); 193 server.updateOptions(updaters);
236 return new Response(request.id); 194 return new Response(request.id);
237 } 195 }
238 } 196 }
239
240
241 /**
242 * A description of the change to the content of a file.
243 */
244 class ContentChange {
245 /**
246 * Type of content change. 'add' means that [content] contains the full
247 * content of the file, and [changes] should be null. 'change' means that
248 * [changes] contains changes to be applied to the file, and [content] should
249 * be null. 'remove' means that the file should be read from the filesystem,
250 * and both [content] and [changes] should be null.
251 */
252 String type;
253
254 String content;
255 List<Edit> changes;
256 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698