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

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

Issue 2525693002: Use single unit/node/element. (Closed)
Patch Set: Created 4 years, 1 month 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
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/plugin/edit/assist/assist_core.dart'; 9 import 'package:analysis_server/plugin/edit/assist/assist_core.dart';
10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart'; 10 import 'package:analysis_server/plugin/edit/assist/assist_dart.dart';
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 newAnalysisError_fromEngine(lineInfo, error); 194 newAnalysisError_fromEngine(lineInfo, error);
195 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError); 195 AnalysisErrorFixes errorFixes = new AnalysisErrorFixes(serverError);
196 errorFixesList.add(errorFixes); 196 errorFixesList.add(errorFixes);
197 fixes.forEach((fix) { 197 fixes.forEach((fix) {
198 errorFixes.fixes.add(fix.change); 198 errorFixes.fixes.add(fix.change);
199 }); 199 });
200 } 200 }
201 } 201 }
202 } 202 }
203 } else { 203 } else {
204 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 204 CompilationUnit unit = server.getResolvedCompilationUnit(file);
205 for (CompilationUnit unit in units) { 205 engine.AnalysisErrorInfo errorInfo = server.getErrors(file);
206 engine.AnalysisErrorInfo errorInfo = server.getErrors(file); 206 if (errorInfo != null) {
207 if (errorInfo != null) { 207 LineInfo lineInfo = errorInfo.lineInfo;
208 LineInfo lineInfo = errorInfo.lineInfo; 208 int requestLine = lineInfo.getLocation(offset).lineNumber;
209 int requestLine = lineInfo.getLocation(offset).lineNumber; 209 for (engine.AnalysisError error in errorInfo.errors) {
210 for (engine.AnalysisError error in errorInfo.errors) { 210 int errorLine = lineInfo.getLocation(error.offset).lineNumber;
211 int errorLine = lineInfo.getLocation(error.offset).lineNumber; 211 if (errorLine == requestLine) {
212 if (errorLine == requestLine) { 212 List<Fix> fixes = await computeFixes(server.serverPlugin,
213 List<Fix> fixes = await computeFixes(server.serverPlugin, 213 server.resourceProvider, unit.element.context, error);
214 server.resourceProvider, unit.element.context, error); 214 if (fixes.isNotEmpty) {
215 if (fixes.isNotEmpty) { 215 AnalysisError serverError =
216 AnalysisError serverError = 216 newAnalysisError_fromEngine(lineInfo, error);
217 newAnalysisError_fromEngine(lineInfo, error); 217 AnalysisErrorFixes errorFixes =
218 AnalysisErrorFixes errorFixes = 218 new AnalysisErrorFixes(serverError);
219 new AnalysisErrorFixes(serverError); 219 errorFixesList.add(errorFixes);
220 errorFixesList.add(errorFixes); 220 fixes.forEach((fix) {
221 fixes.forEach((fix) { 221 errorFixes.fixes.add(fix.change);
222 errorFixes.fixes.add(fix.change); 222 });
223 });
224 }
225 } 223 }
226 } 224 }
227 } 225 }
228 } 226 }
229 } 227 }
230 228
231 // Send the response. 229 // Send the response.
232 server.sendResponse( 230 server.sendResponse(
233 new EditGetFixesResult(errorFixesList).toResponse(request.id)); 231 new EditGetFixesResult(errorFixesList).toResponse(request.id));
234 } 232 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 AnalysisResult result = await server.getAnalysisResult(file); 277 AnalysisResult result = await server.getAnalysisResult(file);
280 if (result == null) { 278 if (result == null) {
281 server.sendResponse(new Response.fileNotAnalyzed(request, file)); 279 server.sendResponse(new Response.fileNotAnalyzed(request, file));
282 return; 280 return;
283 } 281 }
284 fileStamp = -1; 282 fileStamp = -1;
285 code = result.content; 283 code = result.content;
286 unit = result.unit; 284 unit = result.unit;
287 errors = result.errors; 285 errors = result.errors;
288 } else { 286 } else {
289 // prepare resolved units 287 // prepare resolved unit
290 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 288 unit = server.getResolvedCompilationUnit(file);
291 if (units.isEmpty) { 289 if (unit == null) {
292 server.sendResponse(new Response.fileNotAnalyzed(request, file)); 290 server.sendResponse(new Response.fileNotAnalyzed(request, file));
293 return; 291 return;
294 } 292 }
295 // prepare context 293 // prepare context
296 unit = units.first;
297 engine.AnalysisContext context = unit.element.context; 294 engine.AnalysisContext context = unit.element.context;
298 Source source = unit.element.source; 295 Source source = unit.element.source;
299 errors = context.computeErrors(source); 296 errors = context.computeErrors(source);
300 // prepare code 297 // prepare code
301 fileStamp = context.getModificationStamp(source); 298 fileStamp = context.getModificationStamp(source);
302 code = context.getContents(source).data; 299 code = context.getContents(source).data;
303 } 300 }
304 // check if there are scan/parse errors in the file 301 // check if there are scan/parse errors in the file
305 int numScanParseErrors = _getNumberOfScanParseErrors(errors); 302 int numScanParseErrors = _getNumberOfScanParseErrors(errors);
306 if (numScanParseErrors != 0) { 303 if (numScanParseErrors != 0) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 int length = params.length; 390 int length = params.length;
394 // add refactoring kinds 391 // add refactoring kinds
395 List<RefactoringKind> kinds = <RefactoringKind>[]; 392 List<RefactoringKind> kinds = <RefactoringKind>[];
396 // try EXTRACT_* 393 // try EXTRACT_*
397 if (length != 0) { 394 if (length != 0) {
398 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE); 395 kinds.add(RefactoringKind.EXTRACT_LOCAL_VARIABLE);
399 kinds.add(RefactoringKind.EXTRACT_METHOD); 396 kinds.add(RefactoringKind.EXTRACT_METHOD);
400 } 397 }
401 // check elements 398 // check elements
402 { 399 {
403 List<Element> elements = server.getElementsAtOffset(file, offset); 400 Element element = server.getElementAtOffset(file, offset);
404 if (elements.isNotEmpty) { 401 if (element != null) {
405 Element element = elements[0];
406 // try CONVERT_METHOD_TO_GETTER 402 // try CONVERT_METHOD_TO_GETTER
407 if (element is ExecutableElement) { 403 if (element is ExecutableElement) {
408 Refactoring refactoring = 404 Refactoring refactoring =
409 new ConvertMethodToGetterRefactoring(searchEngine, element); 405 new ConvertMethodToGetterRefactoring(searchEngine, element);
410 RefactoringStatus status = await refactoring.checkInitialConditions(); 406 RefactoringStatus status = await refactoring.checkInitialConditions();
411 if (!status.hasFatalError) { 407 if (!status.hasFatalError) {
412 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER); 408 kinds.add(RefactoringKind.CONVERT_METHOD_TO_GETTER);
413 } 409 }
414 } 410 }
415 // try RENAME 411 // try RENAME
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 this.kind = kind; 697 this.kind = kind;
702 this.file = file; 698 this.file = file;
703 this.offset = offset; 699 this.offset = offset;
704 this.length = length; 700 this.length = length;
705 // simulate an exception 701 // simulate an exception
706 if (test_simulateRefactoringException_init) { 702 if (test_simulateRefactoringException_init) {
707 throw 'A simulated refactoring exception - init.'; 703 throw 'A simulated refactoring exception - init.';
708 } 704 }
709 // create a new Refactoring instance 705 // create a new Refactoring instance
710 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) { 706 if (kind == RefactoringKind.CONVERT_GETTER_TO_METHOD) {
711 List<Element> elements = server.getElementsAtOffset(file, offset); 707 Element element = server.getElementAtOffset(file, offset);
712 if (elements.isNotEmpty) { 708 if (element != null) {
713 Element element = elements[0];
714 if (element is ExecutableElement) { 709 if (element is ExecutableElement) {
715 _resetOnAnalysisStarted(); 710 _resetOnAnalysisStarted();
716 refactoring = 711 refactoring =
717 new ConvertGetterToMethodRefactoring(searchEngine, element); 712 new ConvertGetterToMethodRefactoring(searchEngine, element);
718 } 713 }
719 } 714 }
720 } 715 }
721 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) { 716 if (kind == RefactoringKind.CONVERT_METHOD_TO_GETTER) {
722 List<Element> elements = server.getElementsAtOffset(file, offset); 717 Element element = server.getElementAtOffset(file, offset);
723 if (elements.isNotEmpty) { 718 if (element != null) {
724 Element element = elements[0];
725 if (element is ExecutableElement) { 719 if (element is ExecutableElement) {
726 _resetOnAnalysisStarted(); 720 _resetOnAnalysisStarted();
727 refactoring = 721 refactoring =
728 new ConvertMethodToGetterRefactoring(searchEngine, element); 722 new ConvertMethodToGetterRefactoring(searchEngine, element);
729 } 723 }
730 } 724 }
731 } 725 }
732 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) { 726 if (kind == RefactoringKind.EXTRACT_LOCAL_VARIABLE) {
733 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 727 CompilationUnit unit = server.getResolvedCompilationUnit(file);
734 if (units.isNotEmpty) { 728 if (unit != null) {
735 _resetOnFileResolutionChanged(file); 729 _resetOnFileResolutionChanged(file);
736 refactoring = new ExtractLocalRefactoring(units[0], offset, length); 730 refactoring = new ExtractLocalRefactoring(unit, offset, length);
737 feedback = new ExtractLocalVariableFeedback( 731 feedback = new ExtractLocalVariableFeedback(
738 <String>[], <int>[], <int>[], 732 <String>[], <int>[], <int>[],
739 coveringExpressionOffsets: <int>[], 733 coveringExpressionOffsets: <int>[],
740 coveringExpressionLengths: <int>[]); 734 coveringExpressionLengths: <int>[]);
741 } 735 }
742 } 736 }
743 if (kind == RefactoringKind.EXTRACT_METHOD) { 737 if (kind == RefactoringKind.EXTRACT_METHOD) {
744 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 738 CompilationUnit unit = server.getResolvedCompilationUnit(file);
745 if (units.isNotEmpty) { 739 if (unit != null) {
746 _resetOnAnalysisStarted(); 740 _resetOnAnalysisStarted();
747 refactoring = new ExtractMethodRefactoring( 741 refactoring =
748 searchEngine, units[0], offset, length); 742 new ExtractMethodRefactoring(searchEngine, unit, offset, length);
749 feedback = new ExtractMethodFeedback(offset, length, '', <String>[], 743 feedback = new ExtractMethodFeedback(offset, length, '', <String>[],
750 false, <RefactoringMethodParameter>[], <int>[], <int>[]); 744 false, <RefactoringMethodParameter>[], <int>[], <int>[]);
751 } 745 }
752 } 746 }
753 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) { 747 if (kind == RefactoringKind.INLINE_LOCAL_VARIABLE) {
754 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 748 CompilationUnit unit = server.getResolvedCompilationUnit(file);
755 if (units.isNotEmpty) { 749 if (unit != null) {
756 _resetOnFileResolutionChanged(file); 750 _resetOnFileResolutionChanged(file);
757 refactoring = 751 refactoring = new InlineLocalRefactoring(searchEngine, unit, offset);
758 new InlineLocalRefactoring(searchEngine, units[0], offset);
759 } 752 }
760 } 753 }
761 if (kind == RefactoringKind.INLINE_METHOD) { 754 if (kind == RefactoringKind.INLINE_METHOD) {
762 List<CompilationUnit> units = server.getResolvedCompilationUnits(file); 755 CompilationUnit unit = server.getResolvedCompilationUnit(file);
763 if (units.isNotEmpty) { 756 if (unit != null) {
764 _resetOnAnalysisStarted(); 757 _resetOnAnalysisStarted();
765 refactoring = 758 refactoring = new InlineMethodRefactoring(searchEngine, unit, offset);
766 new InlineMethodRefactoring(searchEngine, units[0], offset);
767 } 759 }
768 } 760 }
769 if (kind == RefactoringKind.MOVE_FILE) { 761 if (kind == RefactoringKind.MOVE_FILE) {
770 _resetOnAnalysisStarted(); 762 _resetOnAnalysisStarted();
771 ContextSourcePair contextSource = server.getContextSourcePair(file); 763 ContextSourcePair contextSource = server.getContextSourcePair(file);
772 engine.AnalysisContext context = contextSource.context; 764 engine.AnalysisContext context = contextSource.context;
773 Source source = contextSource.source; 765 Source source = contextSource.source;
774 refactoring = new MoveFileRefactoring( 766 refactoring = new MoveFileRefactoring(
775 server.resourceProvider, searchEngine, context, source, file); 767 server.resourceProvider, searchEngine, context, source, file);
776 } 768 }
777 if (kind == RefactoringKind.RENAME) { 769 if (kind == RefactoringKind.RENAME) {
778 List<AstNode> nodes = server.getNodesAtOffset(file, offset); 770 AstNode node = server.getNodeAtOffset(file, offset);
779 List<Element> elements = server.getElementsOfNodes(nodes); 771 Element element = server.getElementOfNode(node);
780 if (nodes.isNotEmpty && elements.isNotEmpty) { 772 if (node != null && element != null) {
781 AstNode node = nodes[0];
782 Element element = elements[0];
783 if (element is FieldFormalParameterElement) { 773 if (element is FieldFormalParameterElement) {
784 element = (element as FieldFormalParameterElement).field; 774 element = (element as FieldFormalParameterElement).field;
785 } 775 }
786 // climb from "Class" in "new Class.named()" to "Class.named" 776 // climb from "Class" in "new Class.named()" to "Class.named"
787 if (node.parent is TypeName && node.parent.parent is ConstructorName) { 777 if (node.parent is TypeName && node.parent.parent is ConstructorName) {
788 ConstructorName constructor = node.parent.parent; 778 ConstructorName constructor = node.parent.parent;
789 node = constructor; 779 node = constructor;
790 element = constructor.staticElement; 780 element = constructor.staticElement;
791 } 781 }
792 // do create the refactoring 782 // do create the refactoring
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 } 934 }
945 return new RefactoringStatus(); 935 return new RefactoringStatus();
946 } 936 }
947 } 937 }
948 938
949 /** 939 /**
950 * [_RefactoringManager] throws instances of this class internally to stop 940 * [_RefactoringManager] throws instances of this class internally to stop
951 * processing in a manager that was reset. 941 * processing in a manager that was reset.
952 */ 942 */
953 class _ResetError {} 943 class _ResetError {}
OLDNEW
« no previous file with comments | « pkg/analysis_server/lib/src/domain_analysis.dart ('k') | pkg/analysis_server/lib/src/operation/operation_analysis.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698