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

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

Issue 245113006: Consistently type check analysis server request parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 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.context; 5 library domain.context;
6 6
7 import 'package:analysis_server/src/analysis_server.dart'; 7 import 'package:analysis_server/src/analysis_server.dart';
8 import 'package:analysis_server/src/protocol.dart'; 8 import 'package:analysis_server/src/protocol.dart';
9 import 'package:analyzer/src/generated/engine.dart'; 9 import 'package:analyzer/src/generated/engine.dart';
10 import 'package:analyzer/src/generated/source.dart'; 10 import 'package:analyzer/src/generated/source.dart';
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 return null; 128 return null;
129 } 129 }
130 130
131 /** 131 /**
132 * Inform the specified context that the changes encoded in the change set 132 * Inform the specified context that the changes encoded in the change set
133 * have been made. Any invalidated analysis results will be flushed from the 133 * have been made. Any invalidated analysis results will be flushed from the
134 * context. 134 * context.
135 */ 135 */
136 Response applyChanges(Request request) { 136 Response applyChanges(Request request) {
137 AnalysisContext context = getAnalysisContext(request); 137 AnalysisContext context = getAnalysisContext(request);
138 Map<String, Object> changesData = request.getRequiredParameter(CHANGES_PARAM ); 138 RequestDatum changesData = request.getRequiredParameter(CHANGES_PARAM);
139 ChangeSet changeSet = createChangeSet( 139 ChangeSet changeSet = createChangeSet(
140 request, 140 request,
141 context.sourceFactory, 141 context.sourceFactory,
142 changesData); 142 changesData);
143 143
144 context.applyChanges(changeSet); 144 context.applyChanges(changeSet);
145 Response response = new Response(request.id); 145 Response response = new Response(request.id);
146 return response; 146 return response;
147 } 147 }
148 148
149 /** 149 /**
150 * Convert the given JSON object into a [ChangeSet], using the given 150 * Convert the given JSON object into a [ChangeSet], using the given
151 * [sourceFactory] to convert the embedded strings into sources. 151 * [sourceFactory] to convert the embedded strings into sources.
152 */ 152 */
153 ChangeSet createChangeSet(Request request, SourceFactory sourceFactory, Map<St ring, Object> jsonData) { 153 ChangeSet createChangeSet(Request request, SourceFactory sourceFactory,
154 RequestDatum jsonData) {
154 ChangeSet changeSet = new ChangeSet(); 155 ChangeSet changeSet = new ChangeSet();
155 convertSources(request, sourceFactory, jsonData[ADDED_PARAM], (Source source ) { 156 convertSources(request, sourceFactory, jsonData[ADDED_PARAM], (Source source ) {
156 changeSet.addedSource(source); 157 changeSet.addedSource(source);
157 }); 158 });
158 convertSources(request, sourceFactory, jsonData[MODIFIED_PARAM], (Source sou rce) { 159 convertSources(request, sourceFactory, jsonData[MODIFIED_PARAM], (Source sou rce) {
159 changeSet.changedSource(source); 160 changeSet.changedSource(source);
160 }); 161 });
161 convertSources(request, sourceFactory, jsonData[REMOVED_PARAM], (Source sour ce) { 162 convertSources(request, sourceFactory, jsonData[REMOVED_PARAM], (Source sour ce) {
162 changeSet.removedSource(source); 163 changeSet.removedSource(source);
163 }); 164 });
164 return changeSet; 165 return changeSet;
165 } 166 }
166 167
167 /** 168 /**
168 * If the given [sources] is a list of strings, use the given [sourceFactory] 169 * If the given [sources] is a list of strings, use the given [sourceFactory]
169 * to convert each string into a source and pass the source to the given 170 * to convert each string into a source and pass the source to the given
170 * [handler]. Otherwise, throw an exception indicating that the data in the 171 * [handler]. Otherwise, throw an exception indicating that the data in the
171 * request was not valid. 172 * request was not valid.
172 */ 173 */
173 void convertSources(Request request, SourceFactory sourceFactory, Object sourc es, void handler(Source source)) { 174 void convertSources(Request request, SourceFactory sourceFactory, RequestDatum sources, void handler(Source source)) {
174 if (sources is! List<String>) { 175 convertToSources(sourceFactory, sources.asStringList()).forEach(handler);
175 throw new RequestFailure(new Response(request.id, new RequestError(1, 'Inv alid sources')));
176 }
177 convertToSources(sourceFactory, sources).forEach(handler);
178 } 176 }
179 177
180 /** 178 /**
181 * Return the list of fixes that are available for problems related to the 179 * Return the list of fixes that are available for problems related to the
182 * given error in the specified context. 180 * given error in the specified context.
183 */ 181 */
184 Response getFixes(Request request) { 182 Response getFixes(Request request) {
185 // TODO(brianwilkerson) Implement this. 183 // TODO(brianwilkerson) Implement this.
186 Response response = new Response(request.id); 184 Response response = new Response(request.id);
187 return response; 185 return response;
188 } 186 }
189 187
190 /** 188 /**
191 * Set the options controlling analysis within a context to the given set of 189 * Set the options controlling analysis within a context to the given set of
192 * options. 190 * options.
193 */ 191 */
194 Response setOptions(Request request) { 192 Response setOptions(Request request) {
195 AnalysisContext context = getAnalysisContext(request); 193 AnalysisContext context = getAnalysisContext(request);
196 194
197 context.analysisOptions = createAnalysisOptions(request); 195 context.analysisOptions = createAnalysisOptions(request);
198 Response response = new Response(request.id); 196 Response response = new Response(request.id);
199 return response; 197 return response;
200 } 198 }
201 199
202 /** 200 /**
203 * Return the set of analysis options associated with the given [request], or 201 * Return the set of analysis options associated with the given [request], or
204 * throw a [RequestFailure] exception if the analysis options are not valid. 202 * throw a [RequestFailure] exception if the analysis options are not valid.
205 */ 203 */
206 AnalysisOptions createAnalysisOptions(Request request) { 204 AnalysisOptions createAnalysisOptions(Request request) {
207 Map<String, Object> optionsData = request.getRequiredParameter(OPTIONS_PARAM ); 205 RequestDatum optionsData = request.getRequiredParameter(OPTIONS_PARAM);
208 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); 206 AnalysisOptionsImpl options = new AnalysisOptionsImpl();
209 optionsData.forEach((String key, Object value) { 207 optionsData.forEachMap((String key, RequestDatum value) {
210 if (key == CACHE_SIZE_OPTION) { 208 if (key == CACHE_SIZE_OPTION) {
211 options.cacheSize = request.toInt(value); 209 options.cacheSize = value.asInt();
212 } else if (key == GENERATE_HINTS_OPTION) { 210 } else if (key == GENERATE_HINTS_OPTION) {
213 options.hint = request.toBool(value); 211 options.hint = value.asBool();
214 } else if (key == GENERATE_DART2JS_OPTION) { 212 } else if (key == GENERATE_DART2JS_OPTION) {
215 options.dart2jsHint = request.toBool(value); 213 options.dart2jsHint = value.asBool();
216 } else if (key == PROVIDE_ERRORS_OPTION) { 214 } else if (key == PROVIDE_ERRORS_OPTION) {
217 // options.provideErrors = toBool(request, value); 215 // options.provideErrors = value.asBool();
218 } else if (key == PROVIDE_NAVIGATION_OPTION) { 216 } else if (key == PROVIDE_NAVIGATION_OPTION) {
219 // options.provideNavigation = toBool(request, value); 217 // options.provideNavigation = value.asBool();
220 } else if (key == PROVIDE_OUTLINE_OPTION) { 218 } else if (key == PROVIDE_OUTLINE_OPTION) {
221 // options.provideOutline = toBool(request, value); 219 // options.provideOutline = value.asBool();
222 } else { 220 } else {
223 throw new RequestFailure(new Response.unknownAnalysisOption(request, key )); 221 throw new RequestFailure(new Response.unknownAnalysisOption(request, key ));
224 } 222 }
225 }); 223 });
226 return options; 224 return options;
227 } 225 }
228 226
229 /** 227 /**
230 * Set the priority sources in the specified context to the sources in the 228 * Set the priority sources in the specified context to the sources in the
231 * given array. 229 * given array.
232 */ 230 */
233 Response setPrioritySources(Request request) { 231 Response setPrioritySources(Request request) {
234 AnalysisContext context = getAnalysisContext(request); 232 AnalysisContext context = getAnalysisContext(request);
235 List<String> sourcesData = request.getRequiredParameter(SOURCES_PARAM); 233 List<String> sourcesData = request.getRequiredParameter(SOURCES_PARAM).asStr ingList();
236 List<Source> sources = convertToSources(context.sourceFactory, sourcesData); 234 List<Source> sources = convertToSources(context.sourceFactory, sourcesData);
237 235
238 context.analysisPriorityOrder = sources; 236 context.analysisPriorityOrder = sources;
239 Response response = new Response(request.id); 237 Response response = new Response(request.id);
240 return response; 238 return response;
241 } 239 }
242 240
243 /** 241 /**
244 * Convert the given list of strings into a list of sources owned by the given 242 * Convert the given list of strings into a list of sources owned by the given
245 * [sourceFactory]. 243 * [sourceFactory].
246 */ 244 */
247 List<Source> convertToSources(SourceFactory sourceFactory, List<String> source sData) { 245 List<Source> convertToSources(SourceFactory sourceFactory, List<String> source sData) {
248 List<Source> sources = new List<Source>(); 246 List<Source> sources = new List<Source>();
249 sourcesData.forEach((String string) { 247 sourcesData.forEach((String string) {
250 sources.add(sourceFactory.fromEncoding(string)); 248 sources.add(sourceFactory.fromEncoding(string));
251 }); 249 });
252 return sources; 250 return sources;
253 } 251 }
254 252
255 /** 253 /**
256 * Return the analysis context specified by the given request, or throw a 254 * Return the analysis context specified by the given request, or throw a
257 * [RequestFailure] exception if either there is no specified context or if 255 * [RequestFailure] exception if either there is no specified context or if
258 * the specified context does not exist. 256 * the specified context does not exist.
259 */ 257 */
260 AnalysisContext getAnalysisContext(Request request) { 258 AnalysisContext getAnalysisContext(Request request) {
261 String contextId = request.getRequiredParameter(CONTEXT_ID_PARAM); 259 String contextId = request.getRequiredParameter(CONTEXT_ID_PARAM).asString() ;
262 AnalysisContext context = server.contextMap[contextId]; 260 AnalysisContext context = server.contextMap[contextId];
263 if (context == null) { 261 if (context == null) {
264 throw new RequestFailure(new Response.contextDoesNotExist(request)); 262 throw new RequestFailure(new Response.contextDoesNotExist(request));
265 } 263 }
266 return context; 264 return context;
267 } 265 }
268 } 266 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/domain_server.dart » ('j') | pkg/analysis_server/lib/src/protocol.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698