OLD | NEW |
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/plugin/edit/assist/assist_core.dart'; | 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart'; |
10 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; | 10 import 'package:analysis_server/plugin/edit/fix/fix_core.dart'; |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 return new EditOrganizeDirectivesResult(fileEdit).toResponse(request.id); | 243 return new EditOrganizeDirectivesResult(fileEdit).toResponse(request.id); |
244 } | 244 } |
245 | 245 |
246 Response sortMembers(Request request) { | 246 Response sortMembers(Request request) { |
247 var params = new EditSortMembersParams.fromRequest(request); | 247 var params = new EditSortMembersParams.fromRequest(request); |
248 // prepare file | 248 // prepare file |
249 String file = params.file; | 249 String file = params.file; |
250 if (!engine.AnalysisEngine.isDartFileName(file)) { | 250 if (!engine.AnalysisEngine.isDartFileName(file)) { |
251 return new Response.sortMembersInvalidFile(request); | 251 return new Response.sortMembersInvalidFile(request); |
252 } | 252 } |
253 // prepare resolved units | 253 // prepare location |
254 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); | 254 ContextSourcePair contextSource = server.getContextSourcePair(file); |
255 if (units.isEmpty) { | 255 engine.AnalysisContext context = contextSource.context; |
| 256 Source source = contextSource.source; |
| 257 if (context == null || source == null) { |
256 return new Response.sortMembersInvalidFile(request); | 258 return new Response.sortMembersInvalidFile(request); |
257 } | 259 } |
258 // prepare context | 260 // prepare parsed unit |
259 CompilationUnit unit = units.first; | 261 CompilationUnit unit; |
260 engine.AnalysisContext context = unit.element.context; | 262 try { |
261 Source source = unit.element.source; | 263 unit = context.parseCompilationUnit(source); |
| 264 } catch (e) { |
| 265 return new Response.sortMembersInvalidFile(request); |
| 266 } |
262 // check if there are scan/parse errors in the file | 267 // check if there are scan/parse errors in the file |
263 engine.AnalysisErrorInfo errors = context.getErrors(source); | 268 engine.AnalysisErrorInfo errors = context.getErrors(source); |
264 int numScanParseErrors = _getNumberOfScanParseErrors(errors.errors); | 269 int numScanParseErrors = _getNumberOfScanParseErrors(errors.errors); |
265 if (numScanParseErrors != 0) { | 270 if (numScanParseErrors != 0) { |
266 return new Response.sortMembersParseErrors(request, numScanParseErrors); | 271 return new Response.sortMembersParseErrors(request, numScanParseErrors); |
267 } | 272 } |
268 // do sort | 273 // do sort |
269 int fileStamp = context.getModificationStamp(source); | 274 int fileStamp = context.getModificationStamp(source); |
270 String code = context.getContents(source).data; | 275 String code = context.getContents(source).data; |
271 MemberSorter sorter = new MemberSorter(code, unit); | 276 MemberSorter sorter = new MemberSorter(code, unit); |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 } | 746 } |
742 return new RefactoringStatus(); | 747 return new RefactoringStatus(); |
743 } | 748 } |
744 } | 749 } |
745 | 750 |
746 /** | 751 /** |
747 * [_RefactoringManager] throws instances of this class internally to stop | 752 * [_RefactoringManager] throws instances of this class internally to stop |
748 * processing in a manager that was reset. | 753 * processing in a manager that was reset. |
749 */ | 754 */ |
750 class _ResetError {} | 755 class _ResetError {} |
OLD | NEW |