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

Side by Side Diff: pkg/analysis_server/lib/src/edit/edit_domain.dart

Issue 526183002: Integrate EXTRACT_LOCAL_VARIABLE into the server. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 3 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
« no previous file with comments | « no previous file | pkg/analysis_server/test/edit/refactoring_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 edit.domain; 5 library edit.domain;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/analysis_server.dart'; 9 import 'package:analysis_server/src/analysis_server.dart';
10 import 'package:analysis_server/src/constants.dart'; 10 import 'package:analysis_server/src/constants.dart';
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 this.offset == offset && 232 this.offset == offset &&
233 this.length == length) { 233 this.length == length) {
234 return new Future.value(initStatus); 234 return new Future.value(initStatus);
235 } 235 }
236 _reset(); 236 _reset();
237 this.kind = kind; 237 this.kind = kind;
238 this.file = file; 238 this.file = file;
239 this.offset = offset; 239 this.offset = offset;
240 this.length = length; 240 this.length = length;
241 // create a new Refactoring instance 241 // create a new Refactoring instance
242 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
243 List<CompilationUnit> units = server.getResolvedCompilationUnits(file);
244 if (units.isNotEmpty) {
245 refactoring = new ExtractLocalRefactoring(units[0], offset, length);
246 feedback = new ExtractLocalVariableFeedback([], [], []);
247 }
248 }
242 if (kind == RefactoringKind.RENAME) { 249 if (kind == RefactoringKind.RENAME) {
243 List<AstNode> nodes = server.getNodesAtOffset(file, offset); 250 List<AstNode> nodes = server.getNodesAtOffset(file, offset);
244 List<Element> elements = server.getElementsAtOffset(file, offset); 251 List<Element> elements = server.getElementsAtOffset(file, offset);
245 if (nodes.isNotEmpty && elements.isNotEmpty) { 252 if (nodes.isNotEmpty && elements.isNotEmpty) {
246 AstNode node = nodes[0]; 253 AstNode node = nodes[0];
247 Element element = elements[0]; 254 Element element = elements[0];
248 refactoring = new RenameRefactoring(searchEngine, element); 255 refactoring = new RenameRefactoring(searchEngine, element);
249 feedback = new RenameFeedback(node.offset, node.length); 256 feedback = new RenameFeedback(node.offset, node.length);
250 } 257 }
251 } 258 }
252 if (refactoring == null) { 259 if (refactoring == null) {
253 initStatus = 260 initStatus =
254 new RefactoringStatus.fatal('Unable to create a refactoring'); 261 new RefactoringStatus.fatal('Unable to create a refactoring');
255 return new Future.value(initStatus); 262 return new Future.value(initStatus);
256 } 263 }
257 // check initial conditions 264 // check initial conditions
258 return refactoring.checkInitialConditions().then((status) { 265 return refactoring.checkInitialConditions().then((status) {
259 initStatus = status; 266 initStatus = status;
267 if (refactoring is ExtractLocalRefactoring) {
268 ExtractLocalRefactoring refactoring = this.refactoring;
269 ExtractLocalVariableFeedback feedback = this.feedback;
270 feedback.names = refactoring.names;
271 feedback.offsets = refactoring.offsets;
272 feedback.lengths = refactoring.lengths;
273 }
260 return initStatus; 274 return initStatus;
261 }); 275 });
262 } 276 }
263 277
264 void _reset() { 278 void _reset() {
265 refactoring = null; 279 refactoring = null;
266 feedback = null; 280 feedback = null;
267 initStatus = new RefactoringStatus(); 281 initStatus = new RefactoringStatus();
268 optionsStatus = new RefactoringStatus(); 282 optionsStatus = new RefactoringStatus();
269 finalStatus = new RefactoringStatus(); 283 finalStatus = new RefactoringStatus();
(...skipping 10 matching lines...) Expand all
280 result.problems = status.problems; 294 result.problems = status.problems;
281 } 295 }
282 // send the response 296 // send the response
283 server.sendResponse(result.toResponse(requestId)); 297 server.sendResponse(result.toResponse(requestId));
284 // done with this request 298 // done with this request
285 requestId = null; 299 requestId = null;
286 result = null; 300 result = null;
287 } 301 }
288 302
289 RefactoringStatus _setOptions(Object options) { 303 RefactoringStatus _setOptions(Object options) {
304 if (refactoring is ExtractLocalRefactoring) {
305 ExtractLocalRefactoring extractRefactoring = refactoring;
306 ExtractLocalVariableOptions extractOptions = options;
307 extractRefactoring.name = extractOptions.name;
308 extractRefactoring.extractAll = extractOptions.extractAll;
309 return extractRefactoring.checkName();
310 }
290 if (refactoring is RenameRefactoring) { 311 if (refactoring is RenameRefactoring) {
291 RenameRefactoring renameRefactoring = refactoring; 312 RenameRefactoring renameRefactoring = refactoring;
292 RenameOptions renameOptions = options; 313 RenameOptions renameOptions = options;
293 String newName = renameOptions.newName; 314 renameRefactoring.newName = renameOptions.newName;
294 renameRefactoring.newName = newName;
295 return renameRefactoring.checkNewName(); 315 return renameRefactoring.checkNewName();
296 } 316 }
297 return new RefactoringStatus(); 317 return new RefactoringStatus();
298 } 318 }
299 } 319 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/test/edit/refactoring_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698