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

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

Issue 601083005: Implement 'edit.sortMembers' request. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Forgot to add tests Created 6 years, 2 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 | « pkg/analysis_server/lib/src/constants.dart ('k') | pkg/analysis_server/lib/src/protocol.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';
11 import 'package:analysis_server/src/protocol.dart' hide Element; 11 import 'package:analysis_server/src/protocol.dart' hide Element;
12 import 'package:analysis_server/src/services/correction/assist.dart'; 12 import 'package:analysis_server/src/services/correction/assist.dart';
13 import 'package:analysis_server/src/services/correction/fix.dart'; 13 import 'package:analysis_server/src/services/correction/fix.dart';
14 import 'package:analysis_server/src/services/correction/sort_members.dart';
14 import 'package:analysis_server/src/services/correction/status.dart'; 15 import 'package:analysis_server/src/services/correction/status.dart';
15 import 'package:analysis_server/src/services/json.dart'; 16 import 'package:analysis_server/src/services/json.dart';
16 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; 17 import 'package:analysis_server/src/services/refactoring/refactoring.dart';
17 import 'package:analysis_server/src/services/search/search_engine.dart'; 18 import 'package:analysis_server/src/services/search/search_engine.dart';
18 import 'package:analyzer/src/generated/ast.dart'; 19 import 'package:analyzer/src/generated/ast.dart';
19 import 'package:analyzer/src/generated/element.dart'; 20 import 'package:analyzer/src/generated/element.dart';
20 import 'package:analyzer/src/generated/engine.dart' as engine; 21 import 'package:analyzer/src/generated/engine.dart' as engine;
21 import 'package:analyzer/src/generated/error.dart' as engine; 22 import 'package:analyzer/src/generated/error.dart' as engine;
23 import 'package:analyzer/src/generated/parser.dart' as engine;
24 import 'package:analyzer/src/generated/scanner.dart' as engine;
22 import 'package:analyzer/src/generated/source.dart'; 25 import 'package:analyzer/src/generated/source.dart';
23 26
24 27
25 /** 28 /**
26 * Instances of the class [EditDomainHandler] implement a [RequestHandler] 29 * Instances of the class [EditDomainHandler] implement a [RequestHandler]
27 * that handles requests in the edit domain. 30 * that handles requests in the edit domain.
28 */ 31 */
29 class EditDomainHandler implements RequestHandler { 32 class EditDomainHandler implements RequestHandler {
30 /** 33 /**
31 * The analysis server that is using this handler to process requests. 34 * The analysis server that is using this handler to process requests.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 String requestName = request.method; 135 String requestName = request.method;
133 if (requestName == EDIT_GET_ASSISTS) { 136 if (requestName == EDIT_GET_ASSISTS) {
134 return getAssists(request); 137 return getAssists(request);
135 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) { 138 } else if (requestName == EDIT_GET_AVAILABLE_REFACTORINGS) {
136 return getAvailableRefactorings(request); 139 return getAvailableRefactorings(request);
137 } else if (requestName == EDIT_GET_FIXES) { 140 } else if (requestName == EDIT_GET_FIXES) {
138 return getFixes(request); 141 return getFixes(request);
139 } else if (requestName == EDIT_GET_REFACTORING) { 142 } else if (requestName == EDIT_GET_REFACTORING) {
140 refactoringManager.getRefactoring(request); 143 refactoringManager.getRefactoring(request);
141 return Response.DELAYED_RESPONSE; 144 return Response.DELAYED_RESPONSE;
145 } else if (requestName == EDIT_SORT_MEMBERS) {
146 return sortMembers(request);
142 } 147 }
143 } on RequestFailure catch (exception) { 148 } on RequestFailure catch (exception) {
144 return exception.response; 149 return exception.response;
145 } 150 }
146 return null; 151 return null;
147 } 152 }
153
154 Response sortMembers(Request request) {
155 var params = new EditSortMembersParams.fromRequest(request);
156 // prepare file
157 String file = params.file;
158 if (!engine.AnalysisEngine.isDartFileName(file)) {
159 return new Response.sortMembersInvalidFile(request);
160 }
161 // prepare resolved units
162 List<CompilationUnit> units = server.getResolvedCompilationUnits(file);
163 if (units.isEmpty) {
164 return new Response.sortMembersInvalidFile(request);
165 }
166 // prepare context
167 CompilationUnit unit = units.first;
168 engine.AnalysisContext context = unit.element.context;
169 Source source = unit.element.source;
170 // check if there are no scan/parse errors in the file
171 engine.AnalysisErrorInfo errors = context.getErrors(source);
172 int numScanParseErrors = 0;
173 errors.errors.forEach((engine.AnalysisError error) {
174 if (error.errorCode is engine.ScannerErrorCode ||
175 error.errorCode is engine.ParserErrorCode) {
176 numScanParseErrors++;
177 }
178 });
179 if (numScanParseErrors != 0) {
180 return new Response.sortMembersParseErrors(request, numScanParseErrors);
181 }
182 // do sort
183 int fileStamp = context.getModificationStamp(source);
184 String code = context.getContents(source).data;
185 MemberSorter sorter = new MemberSorter(code, unit);
186 List<SourceEdit> edits = sorter.sort();
187 SourceFileEdit fileEdit = new SourceFileEdit(file, fileStamp, edits: edits);
188 return new EditSortMembersResult(fileEdit).toResponse(request.id);
189 }
148 } 190 }
149 191
150 192
151 /** 193 /**
152 * An object managing a single [Refactoring] instance. 194 * An object managing a single [Refactoring] instance.
153 * 195 *
154 * The instance is identified by its kind, file, offset and length. 196 * The instance is identified by its kind, file, offset and length.
155 * It is initialized when the a set of parameters is given for the first time. 197 * It is initialized when the a set of parameters is given for the first time.
156 * All subsequent requests are performed on this [Refactoring] instance. 198 * All subsequent requests are performed on this [Refactoring] instance.
157 * 199 *
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 } 490 }
449 if (refactoring is RenameRefactoring) { 491 if (refactoring is RenameRefactoring) {
450 RenameRefactoring renameRefactoring = refactoring; 492 RenameRefactoring renameRefactoring = refactoring;
451 RenameOptions renameOptions = params.options; 493 RenameOptions renameOptions = params.options;
452 renameRefactoring.newName = renameOptions.newName; 494 renameRefactoring.newName = renameOptions.newName;
453 return renameRefactoring.checkNewName(); 495 return renameRefactoring.checkNewName();
454 } 496 }
455 return new RefactoringStatus(); 497 return new RefactoringStatus();
456 } 498 }
457 } 499 }
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/constants.dart ('k') | pkg/analysis_server/lib/src/protocol.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698