| 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 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 | 193 |
| 194 /** | 194 /** |
| 195 * [InlineMethodRefactoring] implementation. | 195 * [InlineMethodRefactoring] implementation. |
| 196 */ | 196 */ |
| 197 class InlineMethodRefactoringImpl extends RefactoringImpl | 197 class InlineMethodRefactoringImpl extends RefactoringImpl |
| 198 implements InlineMethodRefactoring { | 198 implements InlineMethodRefactoring { |
| 199 final SearchEngine searchEngine; | 199 final SearchEngine searchEngine; |
| 200 final AstProvider astProvider; | 200 final AstProvider astProvider; |
| 201 final CompilationUnit unit; | 201 final CompilationUnit unit; |
| 202 final int offset; | 202 final int offset; |
| 203 _UnitCache _unitCache; | 203 ResolvedUnitCache _unitCache; |
| 204 CorrectionUtils utils; | 204 CorrectionUtils utils; |
| 205 SourceChange change; | 205 SourceChange change; |
| 206 | 206 |
| 207 bool isDeclaration = false; | 207 bool isDeclaration = false; |
| 208 bool deleteSource = false; | 208 bool deleteSource = false; |
| 209 bool inlineAll = true; | 209 bool inlineAll = true; |
| 210 | 210 |
| 211 ExecutableElement _methodElement; | 211 ExecutableElement _methodElement; |
| 212 bool _isAccessor; | 212 bool _isAccessor; |
| 213 CompilationUnit _methodUnit; | 213 CompilationUnit _methodUnit; |
| 214 CorrectionUtils _methodUtils; | 214 CorrectionUtils _methodUtils; |
| 215 AstNode _methodNode; | 215 AstNode _methodNode; |
| 216 FormalParameterList _methodParameters; | 216 FormalParameterList _methodParameters; |
| 217 FunctionBody _methodBody; | 217 FunctionBody _methodBody; |
| 218 Expression _methodExpression; | 218 Expression _methodExpression; |
| 219 _SourcePart _methodExpressionPart; | 219 _SourcePart _methodExpressionPart; |
| 220 _SourcePart _methodStatementsPart; | 220 _SourcePart _methodStatementsPart; |
| 221 List<_ReferenceProcessor> _referenceProcessors = []; | 221 List<_ReferenceProcessor> _referenceProcessors = []; |
| 222 Set<FunctionBody> _alreadyMadeAsync = new Set<FunctionBody>(); | 222 Set<FunctionBody> _alreadyMadeAsync = new Set<FunctionBody>(); |
| 223 | 223 |
| 224 InlineMethodRefactoringImpl( | 224 InlineMethodRefactoringImpl( |
| 225 this.searchEngine, this.astProvider, this.unit, this.offset) { | 225 this.searchEngine, this.astProvider, this.unit, this.offset) { |
| 226 _unitCache = new _UnitCache(astProvider, unit); | 226 _unitCache = new ResolvedUnitCache(astProvider, unit); |
| 227 utils = new CorrectionUtils(unit); | 227 utils = new CorrectionUtils(unit); |
| 228 } | 228 } |
| 229 | 229 |
| 230 @override | 230 @override |
| 231 String get className { | 231 String get className { |
| 232 if (_methodElement == null) { | 232 if (_methodElement == null) { |
| 233 return null; | 233 return null; |
| 234 } | 234 } |
| 235 Element classElement = _methodElement.enclosingElement; | 235 Element classElement = _methodElement.enclosingElement; |
| 236 if (classElement is ClassElement) { | 236 if (classElement is ClassElement) { |
| (...skipping 545 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 List<SourceRange> ranges = _variables[element]; | 782 List<SourceRange> ranges = _variables[element]; |
| 783 if (ranges == null) { | 783 if (ranges == null) { |
| 784 ranges = []; | 784 ranges = []; |
| 785 _variables[element] = ranges; | 785 _variables[element] = ranges; |
| 786 } | 786 } |
| 787 range = rangeFromBase(range, _base); | 787 range = rangeFromBase(range, _base); |
| 788 ranges.add(range); | 788 ranges.add(range); |
| 789 } | 789 } |
| 790 } | 790 } |
| 791 | 791 |
| 792 class _UnitCache { | |
| 793 final AstProvider astProvider; | |
| 794 final Map<CompilationUnitElement, CompilationUnit> map = {}; | |
| 795 | |
| 796 _UnitCache(this.astProvider, CompilationUnit unit) { | |
| 797 map[unit.element] = unit; | |
| 798 } | |
| 799 | |
| 800 Future<CompilationUnit> getUnit(Element element) async { | |
| 801 Element unitElement = | |
| 802 element.getAncestor((e) => e is CompilationUnitElement); | |
| 803 CompilationUnit unit = map[unitElement]; | |
| 804 if (unit == null) { | |
| 805 unit = await astProvider.getResolvedUnitForElement(element); | |
| 806 map[unitElement] = unit; | |
| 807 } | |
| 808 return unit; | |
| 809 } | |
| 810 } | |
| 811 | |
| 812 /** | 792 /** |
| 813 * A visitor that fills [_SourcePart] with fields, parameters and variables. | 793 * A visitor that fills [_SourcePart] with fields, parameters and variables. |
| 814 */ | 794 */ |
| 815 class _VariablesVisitor extends GeneralizingAstVisitor { | 795 class _VariablesVisitor extends GeneralizingAstVisitor { |
| 816 /** | 796 /** |
| 817 * The [ExecutableElement] being inlined. | 797 * The [ExecutableElement] being inlined. |
| 818 */ | 798 */ |
| 819 final ExecutableElement methodElement; | 799 final ExecutableElement methodElement; |
| 820 | 800 |
| 821 /** | 801 /** |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 } | 882 } |
| 903 | 883 |
| 904 void _addVariable(SimpleIdentifier node) { | 884 void _addVariable(SimpleIdentifier node) { |
| 905 VariableElement variableElement = getLocalVariableElement(node); | 885 VariableElement variableElement = getLocalVariableElement(node); |
| 906 if (variableElement != null) { | 886 if (variableElement != null) { |
| 907 SourceRange nodeRange = rangeNode(node); | 887 SourceRange nodeRange = rangeNode(node); |
| 908 result.addVariable(variableElement, nodeRange); | 888 result.addVariable(variableElement, nodeRange); |
| 909 } | 889 } |
| 910 } | 890 } |
| 911 } | 891 } |
| OLD | NEW |