| 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'; |
| 11 import 'package:analysis_server/src/services/correction/status.dart'; | 11 import 'package:analysis_server/src/services/correction/status.dart'; |
| 12 import 'package:analysis_server/src/services/correction/strings.dart'; | 12 import 'package:analysis_server/src/services/correction/strings.dart'; |
| 13 import 'package:analysis_server/src/services/correction/util.dart'; | 13 import 'package:analysis_server/src/services/correction/util.dart'; |
| 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 14 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 15 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; | 15 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; |
| 16 import 'package:analysis_server/src/services/search/element_visitors.dart'; | 16 import 'package:analysis_server/src/services/search/element_visitors.dart'; |
| 17 import 'package:analysis_server/src/services/search/hierarchy.dart'; | 17 import 'package:analysis_server/src/services/search/hierarchy.dart'; |
| 18 import 'package:analysis_server/src/services/search/search_engine.dart'; | 18 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 19 import 'package:analyzer/dart/ast/ast.dart'; | 19 import 'package:analyzer/dart/ast/ast.dart'; |
| 20 import 'package:analyzer/dart/ast/visitor.dart'; | 20 import 'package:analyzer/dart/ast/visitor.dart'; |
| 21 import 'package:analyzer/dart/element/element.dart'; | 21 import 'package:analyzer/dart/element/element.dart'; |
| 22 import 'package:analyzer/src/dart/ast/utilities.dart'; | 22 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 23 import 'package:analyzer/src/dart/element/ast_provider.dart'; |
| 23 import 'package:analyzer/src/generated/source.dart'; | 24 import 'package:analyzer/src/generated/source.dart'; |
| 24 import 'package:analyzer/src/generated/utilities_dart.dart'; | 25 import 'package:analyzer/src/generated/utilities_dart.dart'; |
| 25 | 26 |
| 26 /** | 27 /** |
| 27 * Returns the [SourceRange] to find conflicting locals in. | 28 * Returns the [SourceRange] to find conflicting locals in. |
| 28 */ | 29 */ |
| 29 SourceRange _getLocalsConflictingRange(AstNode node) { | 30 SourceRange _getLocalsConflictingRange(AstNode node) { |
| 30 // maybe Block | 31 // maybe Block |
| 31 Block block = node.getAncestor((node) => node is Block); | 32 Block block = node.getAncestor((node) => node is Block); |
| 32 if (block != null) { | 33 if (block != null) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 // done | 190 // done |
| 190 return result; | 191 return result; |
| 191 } | 192 } |
| 192 | 193 |
| 193 /** | 194 /** |
| 194 * [InlineMethodRefactoring] implementation. | 195 * [InlineMethodRefactoring] implementation. |
| 195 */ | 196 */ |
| 196 class InlineMethodRefactoringImpl extends RefactoringImpl | 197 class InlineMethodRefactoringImpl extends RefactoringImpl |
| 197 implements InlineMethodRefactoring { | 198 implements InlineMethodRefactoring { |
| 198 final SearchEngine searchEngine; | 199 final SearchEngine searchEngine; |
| 199 final GetResolvedUnit getResolvedUnit; | 200 final AstProvider astProvider; |
| 200 final CompilationUnit unit; | 201 final CompilationUnit unit; |
| 201 final int offset; | 202 final int offset; |
| 202 _UnitCache _unitCache; | 203 _UnitCache _unitCache; |
| 203 CorrectionUtils utils; | 204 CorrectionUtils utils; |
| 204 SourceChange change; | 205 SourceChange change; |
| 205 | 206 |
| 206 bool isDeclaration = false; | 207 bool isDeclaration = false; |
| 207 bool deleteSource = false; | 208 bool deleteSource = false; |
| 208 bool inlineAll = true; | 209 bool inlineAll = true; |
| 209 | 210 |
| 210 ExecutableElement _methodElement; | 211 ExecutableElement _methodElement; |
| 211 bool _isAccessor; | 212 bool _isAccessor; |
| 212 CompilationUnit _methodUnit; | 213 CompilationUnit _methodUnit; |
| 213 CorrectionUtils _methodUtils; | 214 CorrectionUtils _methodUtils; |
| 214 AstNode _methodNode; | 215 AstNode _methodNode; |
| 215 FormalParameterList _methodParameters; | 216 FormalParameterList _methodParameters; |
| 216 FunctionBody _methodBody; | 217 FunctionBody _methodBody; |
| 217 Expression _methodExpression; | 218 Expression _methodExpression; |
| 218 _SourcePart _methodExpressionPart; | 219 _SourcePart _methodExpressionPart; |
| 219 _SourcePart _methodStatementsPart; | 220 _SourcePart _methodStatementsPart; |
| 220 List<_ReferenceProcessor> _referenceProcessors = []; | 221 List<_ReferenceProcessor> _referenceProcessors = []; |
| 221 Set<FunctionBody> _alreadyMadeAsync = new Set<FunctionBody>(); | 222 Set<FunctionBody> _alreadyMadeAsync = new Set<FunctionBody>(); |
| 222 | 223 |
| 223 InlineMethodRefactoringImpl( | 224 InlineMethodRefactoringImpl( |
| 224 this.searchEngine, this.getResolvedUnit, this.unit, this.offset) { | 225 this.searchEngine, this.astProvider, this.unit, this.offset) { |
| 225 _unitCache = new _UnitCache(getResolvedUnit, unit); | 226 _unitCache = new _UnitCache(astProvider, unit); |
| 226 utils = new CorrectionUtils(unit); | 227 utils = new CorrectionUtils(unit); |
| 227 } | 228 } |
| 228 | 229 |
| 229 @override | 230 @override |
| 230 String get className { | 231 String get className { |
| 231 if (_methodElement == null) { | 232 if (_methodElement == null) { |
| 232 return null; | 233 return null; |
| 233 } | 234 } |
| 234 Element classElement = _methodElement.enclosingElement; | 235 Element classElement = _methodElement.enclosingElement; |
| 235 if (classElement is ClassElement) { | 236 if (classElement is ClassElement) { |
| (...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 782 if (ranges == null) { | 783 if (ranges == null) { |
| 783 ranges = []; | 784 ranges = []; |
| 784 _variables[element] = ranges; | 785 _variables[element] = ranges; |
| 785 } | 786 } |
| 786 range = rangeFromBase(range, _base); | 787 range = rangeFromBase(range, _base); |
| 787 ranges.add(range); | 788 ranges.add(range); |
| 788 } | 789 } |
| 789 } | 790 } |
| 790 | 791 |
| 791 class _UnitCache { | 792 class _UnitCache { |
| 792 final GetResolvedUnit getResolvedUnit; | 793 final AstProvider astProvider; |
| 793 final Map<CompilationUnitElement, CompilationUnit> map = {}; | 794 final Map<CompilationUnitElement, CompilationUnit> map = {}; |
| 794 | 795 |
| 795 _UnitCache(this.getResolvedUnit, CompilationUnit unit) { | 796 _UnitCache(this.astProvider, CompilationUnit unit) { |
| 796 map[unit.element] = unit; | 797 map[unit.element] = unit; |
| 797 } | 798 } |
| 798 | 799 |
| 799 Future<CompilationUnit> getUnit(Element element) async { | 800 Future<CompilationUnit> getUnit(Element element) async { |
| 800 Element unitElement = | 801 Element unitElement = |
| 801 element.getAncestor((e) => e is CompilationUnitElement); | 802 element.getAncestor((e) => e is CompilationUnitElement); |
| 802 CompilationUnit unit = map[unitElement]; | 803 CompilationUnit unit = map[unitElement]; |
| 803 if (unit == null) { | 804 if (unit == null) { |
| 804 unit = unitElement.unit; | 805 unit = await astProvider.getResolvedUnitForElement(element); |
| 805 map[unitElement] = unit; | 806 map[unitElement] = unit; |
| 806 } | 807 } |
| 807 return unit; | 808 return unit; |
| 808 } | 809 } |
| 809 } | 810 } |
| 810 | 811 |
| 811 /** | 812 /** |
| 812 * A visitor that fills [_SourcePart] with fields, parameters and variables. | 813 * A visitor that fills [_SourcePart] with fields, parameters and variables. |
| 813 */ | 814 */ |
| 814 class _VariablesVisitor extends GeneralizingAstVisitor { | 815 class _VariablesVisitor extends GeneralizingAstVisitor { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 901 } | 902 } |
| 902 | 903 |
| 903 void _addVariable(SimpleIdentifier node) { | 904 void _addVariable(SimpleIdentifier node) { |
| 904 VariableElement variableElement = getLocalVariableElement(node); | 905 VariableElement variableElement = getLocalVariableElement(node); |
| 905 if (variableElement != null) { | 906 if (variableElement != null) { |
| 906 SourceRange nodeRange = rangeNode(node); | 907 SourceRange nodeRange = rangeNode(node); |
| 907 result.addVariable(variableElement, nodeRange); | 908 result.addVariable(variableElement, nodeRange); |
| 908 } | 909 } |
| 909 } | 910 } |
| 910 } | 911 } |
| OLD | NEW |