| 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_local; | 5 library services.src.refactoring.inline_local; |
| 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/util.dart'; | 12 import 'package:analysis_server/src/services/correction/util.dart'; |
| 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; | 13 import 'package:analysis_server/src/services/refactoring/refactoring.dart'; |
| 14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; | 14 import 'package:analysis_server/src/services/refactoring/refactoring_internal.da
rt'; |
| 15 import 'package:analysis_server/src/services/search/search_engine.dart'; | 15 import 'package:analysis_server/src/services/search/search_engine.dart'; |
| 16 import 'package:analyzer/dart/ast/ast.dart'; | 16 import 'package:analyzer/dart/ast/ast.dart'; |
| 17 import 'package:analyzer/dart/ast/token.dart'; | 17 import 'package:analyzer/dart/ast/token.dart'; |
| 18 import 'package:analyzer/dart/element/element.dart'; | 18 import 'package:analyzer/dart/element/element.dart'; |
| 19 import 'package:analyzer/src/dart/ast/utilities.dart'; | 19 import 'package:analyzer/src/dart/ast/utilities.dart'; |
| 20 import 'package:analyzer/src/dart/element/ast_provider.dart'; |
| 20 import 'package:analyzer/src/generated/java_core.dart'; | 21 import 'package:analyzer/src/generated/java_core.dart'; |
| 21 import 'package:analyzer/src/generated/source.dart'; | 22 import 'package:analyzer/src/generated/source.dart'; |
| 22 | 23 |
| 23 /** | 24 /** |
| 24 * [InlineLocalRefactoring] implementation. | 25 * [InlineLocalRefactoring] implementation. |
| 25 */ | 26 */ |
| 26 class InlineLocalRefactoringImpl extends RefactoringImpl | 27 class InlineLocalRefactoringImpl extends RefactoringImpl |
| 27 implements InlineLocalRefactoring { | 28 implements InlineLocalRefactoring { |
| 28 final SearchEngine searchEngine; | 29 final SearchEngine searchEngine; |
| 30 final AstProvider astProvider; |
| 29 final CompilationUnit unit; | 31 final CompilationUnit unit; |
| 30 final int offset; | 32 final int offset; |
| 31 CompilationUnitElement unitElement; | 33 CompilationUnitElement unitElement; |
| 32 CorrectionUtils utils; | 34 CorrectionUtils utils; |
| 33 | 35 |
| 34 Element _variableElement; | 36 Element _variableElement; |
| 35 VariableDeclaration _variableNode; | 37 VariableDeclaration _variableNode; |
| 36 List<SearchMatch> _references; | 38 List<SearchMatch> _references; |
| 37 | 39 |
| 38 InlineLocalRefactoringImpl(this.searchEngine, this.unit, this.offset) { | 40 InlineLocalRefactoringImpl(this.searchEngine, this.astProvider, this.unit, thi
s.offset) { |
| 39 unitElement = unit.element; | 41 unitElement = unit.element; |
| 40 utils = new CorrectionUtils(unit); | 42 utils = new CorrectionUtils(unit); |
| 41 } | 43 } |
| 42 | 44 |
| 43 @override | 45 @override |
| 44 String get refactoringName => 'Inline Local Variable'; | 46 String get refactoringName => 'Inline Local Variable'; |
| 45 | 47 |
| 46 @override | 48 @override |
| 47 int get referenceCount { | 49 int get referenceCount { |
| 48 if (_references == null) { | 50 if (_references == null) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 68 @override | 70 @override |
| 69 Future<RefactoringStatus> checkInitialConditions() async { | 71 Future<RefactoringStatus> checkInitialConditions() async { |
| 70 RefactoringStatus result = new RefactoringStatus(); | 72 RefactoringStatus result = new RefactoringStatus(); |
| 71 // prepare variable | 73 // prepare variable |
| 72 { | 74 { |
| 73 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit); | 75 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit); |
| 74 if (offsetNode is SimpleIdentifier) { | 76 if (offsetNode is SimpleIdentifier) { |
| 75 Element element = offsetNode.staticElement; | 77 Element element = offsetNode.staticElement; |
| 76 if (element is LocalVariableElement) { | 78 if (element is LocalVariableElement) { |
| 77 _variableElement = element; | 79 _variableElement = element; |
| 78 _variableNode = element.computeNode(); | 80 _variableNode = await astProvider.getResolvedNodeForElement(element); |
| 79 } | 81 } |
| 80 } | 82 } |
| 81 } | 83 } |
| 82 // validate node declaration | 84 // validate node declaration |
| 83 if (!_isVariableDeclaredInStatement()) { | 85 if (!_isVariableDeclaredInStatement()) { |
| 84 result = new RefactoringStatus.fatal( | 86 result = new RefactoringStatus.fatal( |
| 85 'Local variable declaration or reference must be selected ' | 87 'Local variable declaration or reference must be selected ' |
| 86 'to activate this refactoring.'); | 88 'to activate this refactoring.'); |
| 87 return new Future<RefactoringStatus>.value(result); | 89 return new Future<RefactoringStatus>.value(result); |
| 88 } | 90 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 if (initializerOperator == TokenType.MINUS || | 204 if (initializerOperator == TokenType.MINUS || |
| 203 initializerOperator == TokenType.MINUS_MINUS) { | 205 initializerOperator == TokenType.MINUS_MINUS) { |
| 204 return true; | 206 return true; |
| 205 } | 207 } |
| 206 } | 208 } |
| 207 } | 209 } |
| 208 // no () is needed | 210 // no () is needed |
| 209 return false; | 211 return false; |
| 210 } | 212 } |
| 211 } | 213 } |
| OLD | NEW |