| 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'; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 final AstProvider astProvider; | 30 final AstProvider astProvider; |
| 31 final CompilationUnit unit; | 31 final CompilationUnit unit; |
| 32 final int offset; | 32 final int offset; |
| 33 CompilationUnitElement unitElement; | 33 CompilationUnitElement unitElement; |
| 34 CorrectionUtils utils; | 34 CorrectionUtils utils; |
| 35 | 35 |
| 36 Element _variableElement; | 36 Element _variableElement; |
| 37 VariableDeclaration _variableNode; | 37 VariableDeclaration _variableNode; |
| 38 List<SearchMatch> _references; | 38 List<SearchMatch> _references; |
| 39 | 39 |
| 40 InlineLocalRefactoringImpl(this.searchEngine, this.astProvider, this.unit, thi
s.offset) { | 40 InlineLocalRefactoringImpl( |
| 41 this.searchEngine, this.astProvider, this.unit, this.offset) { |
| 41 unitElement = unit.element; | 42 unitElement = unit.element; |
| 42 utils = new CorrectionUtils(unit); | 43 utils = new CorrectionUtils(unit); |
| 43 } | 44 } |
| 44 | 45 |
| 45 @override | 46 @override |
| 46 String get refactoringName => 'Inline Local Variable'; | 47 String get refactoringName => 'Inline Local Variable'; |
| 47 | 48 |
| 48 @override | 49 @override |
| 49 int get referenceCount { | 50 int get referenceCount { |
| 50 if (_references == null) { | 51 if (_references == null) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 70 @override | 71 @override |
| 71 Future<RefactoringStatus> checkInitialConditions() async { | 72 Future<RefactoringStatus> checkInitialConditions() async { |
| 72 RefactoringStatus result = new RefactoringStatus(); | 73 RefactoringStatus result = new RefactoringStatus(); |
| 73 // prepare variable | 74 // prepare variable |
| 74 { | 75 { |
| 75 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit); | 76 AstNode offsetNode = new NodeLocator(offset).searchWithin(unit); |
| 76 if (offsetNode is SimpleIdentifier) { | 77 if (offsetNode is SimpleIdentifier) { |
| 77 Element element = offsetNode.staticElement; | 78 Element element = offsetNode.staticElement; |
| 78 if (element is LocalVariableElement) { | 79 if (element is LocalVariableElement) { |
| 79 _variableElement = element; | 80 _variableElement = element; |
| 80 _variableNode = await astProvider.getResolvedNodeForElement(element); | 81 AstNode name = await astProvider.getResolvedNameForElement(element); |
| 82 _variableNode = name.parent as VariableDeclaration; |
| 81 } | 83 } |
| 82 } | 84 } |
| 83 } | 85 } |
| 84 // validate node declaration | 86 // validate node declaration |
| 85 if (!_isVariableDeclaredInStatement()) { | 87 if (!_isVariableDeclaredInStatement()) { |
| 86 result = new RefactoringStatus.fatal( | 88 result = new RefactoringStatus.fatal( |
| 87 'Local variable declaration or reference must be selected ' | 89 'Local variable declaration or reference must be selected ' |
| 88 'to activate this refactoring.'); | 90 'to activate this refactoring.'); |
| 89 return new Future<RefactoringStatus>.value(result); | 91 return new Future<RefactoringStatus>.value(result); |
| 90 } | 92 } |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if (initializerOperator == TokenType.MINUS || | 206 if (initializerOperator == TokenType.MINUS || |
| 205 initializerOperator == TokenType.MINUS_MINUS) { | 207 initializerOperator == TokenType.MINUS_MINUS) { |
| 206 return true; | 208 return true; |
| 207 } | 209 } |
| 208 } | 210 } |
| 209 } | 211 } |
| 210 // no () is needed | 212 // no () is needed |
| 211 return false; | 213 return false; |
| 212 } | 214 } |
| 213 } | 215 } |
| OLD | NEW |