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

Side by Side Diff: pkg/analysis_server/lib/src/services/refactoring/inline_method.dart

Issue 2463493002: Fix for inlining async methods/getters. (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 services.src.refactoring.inline_method; 5 library services.src.refactoring.inline_method;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 8
9 import 'package:analysis_server/src/protocol_server.dart' hide Element; 9 import 'package:analysis_server/src/protocol_server.dart' hide Element;
10 import 'package:analysis_server/src/services/correction/source_range.dart'; 10 import 'package:analysis_server/src/services/correction/source_range.dart';
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 bool _isAccessor; 209 bool _isAccessor;
210 CompilationUnit _methodUnit; 210 CompilationUnit _methodUnit;
211 CorrectionUtils _methodUtils; 211 CorrectionUtils _methodUtils;
212 AstNode _methodNode; 212 AstNode _methodNode;
213 FormalParameterList _methodParameters; 213 FormalParameterList _methodParameters;
214 FunctionBody _methodBody; 214 FunctionBody _methodBody;
215 Expression _methodExpression; 215 Expression _methodExpression;
216 _SourcePart _methodExpressionPart; 216 _SourcePart _methodExpressionPart;
217 _SourcePart _methodStatementsPart; 217 _SourcePart _methodStatementsPart;
218 List<_ReferenceProcessor> _referenceProcessors = []; 218 List<_ReferenceProcessor> _referenceProcessors = [];
219 Set<FunctionBody> _alreadyMadeAsync = new Set<FunctionBody>();
219 220
220 InlineMethodRefactoringImpl(this.searchEngine, this.unit, this.offset) { 221 InlineMethodRefactoringImpl(this.searchEngine, this.unit, this.offset) {
221 utils = new CorrectionUtils(unit); 222 utils = new CorrectionUtils(unit);
222 } 223 }
223 224
224 @override 225 @override
225 String get className { 226 String get className {
226 if (_methodElement == null) { 227 if (_methodElement == null) {
227 return null; 228 return null;
228 } 229 }
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
553 SourceEdit edit = newSourceEdit_range(range, source); 554 SourceEdit edit = newSourceEdit_range(range, source);
554 _addRefEdit(edit); 555 _addRefEdit(edit);
555 } 556 }
556 557
557 void _process(RefactoringStatus status) { 558 void _process(RefactoringStatus status) {
558 AstNode nodeParent = _node.parent; 559 AstNode nodeParent = _node.parent;
559 // may be only single place should be inlined 560 // may be only single place should be inlined
560 if (!_shouldProcess()) { 561 if (!_shouldProcess()) {
561 return; 562 return;
562 } 563 }
564 // If the element being inlined is async, ensure that the function
565 // body that encloses the method is also async.
566 if (ref._methodElement.isAsynchronous) {
567 FunctionBody body = _node.getAncestor((n) => n is FunctionBody);
568 if (!body.isAsynchronous && ref._alreadyMadeAsync.add(body)) {
569 SourceRange bodyStart = rangeStartLength(body.offset, 0);
570 _addRefEdit(newSourceEdit_range(bodyStart, 'async '));
571 }
572 }
563 // may be invocation of inline method 573 // may be invocation of inline method
564 if (nodeParent is MethodInvocation) { 574 if (nodeParent is MethodInvocation) {
565 MethodInvocation invocation = nodeParent; 575 MethodInvocation invocation = nodeParent;
566 Expression target = invocation.target; 576 Expression target = invocation.target;
567 List<Expression> arguments = invocation.argumentList.arguments; 577 List<Expression> arguments = invocation.argumentList.arguments;
568 _inlineMethodInvocation( 578 _inlineMethodInvocation(
569 status, invocation, invocation.isCascaded, target, arguments); 579 status, invocation, invocation.isCascaded, target, arguments);
570 } else { 580 } else {
571 // cannot inline reference to method: var v = new A().method; 581 // cannot inline reference to method: var v = new A().method;
572 if (ref._methodElement is MethodElement) { 582 if (ref._methodElement is MethodElement) {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 } 835 }
826 836
827 void _addVariable(SimpleIdentifier node) { 837 void _addVariable(SimpleIdentifier node) {
828 VariableElement variableElement = getLocalVariableElement(node); 838 VariableElement variableElement = getLocalVariableElement(node);
829 if (variableElement != null) { 839 if (variableElement != null) {
830 SourceRange nodeRange = rangeNode(node); 840 SourceRange nodeRange = rangeNode(node);
831 result.addVariable(variableElement, nodeRange); 841 result.addVariable(variableElement, nodeRange);
832 } 842 }
833 } 843 }
834 } 844 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698