| 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.extract_local; | 5 library services.src.refactoring.extract_local; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 | 9 |
| 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; | 10 import 'package:analysis_server/src/protocol_server.dart' hide Element; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 int numLeading = countLeadingWhitespaces(selectionStr); | 190 int numLeading = countLeadingWhitespaces(selectionStr); |
| 191 int numTrailing = countTrailingWhitespaces(selectionStr); | 191 int numTrailing = countTrailingWhitespaces(selectionStr); |
| 192 int offset = selectionRange.offset + numLeading; | 192 int offset = selectionRange.offset + numLeading; |
| 193 int end = selectionRange.end - numTrailing; | 193 int end = selectionRange.end - numTrailing; |
| 194 selectionRange = new SourceRange(offset, end - offset); | 194 selectionRange = new SourceRange(offset, end - offset); |
| 195 } | 195 } |
| 196 // get covering node | 196 // get covering node |
| 197 AstNode coveringNode = new NodeLocator( | 197 AstNode coveringNode = new NodeLocator( |
| 198 selectionRange.offset, selectionRange.end).searchWithin(unit); | 198 selectionRange.offset, selectionRange.end).searchWithin(unit); |
| 199 // compute covering expressions | 199 // compute covering expressions |
| 200 for (AstNode node = coveringNode; node is Expression; node = node.parent) { | 200 for (AstNode node = coveringNode; |
| 201 node is Expression || node is ArgumentList; |
| 202 node = node.parent) { |
| 201 AstNode parent = node.parent; | 203 AstNode parent = node.parent; |
| 204 // skip ArgumentList |
| 205 if (node is ArgumentList) { |
| 206 continue; |
| 207 } |
| 208 // skip AssignmentExpression |
| 209 if (node is AssignmentExpression) { |
| 210 continue; |
| 211 } |
| 202 // cannot extract the name part of a property access | 212 // cannot extract the name part of a property access |
| 203 if (parent is PrefixedIdentifier && parent.identifier == node || | 213 if (parent is PrefixedIdentifier && parent.identifier == node || |
| 204 parent is PropertyAccess && parent.propertyName == node) { | 214 parent is PropertyAccess && parent.propertyName == node) { |
| 205 continue; | 215 continue; |
| 206 } | 216 } |
| 207 // fatal selection problems | 217 // fatal selection problems |
| 208 if (coveringExpressionOffsets.isEmpty) { | 218 if (coveringExpressionOffsets.isEmpty) { |
| 209 if (node is SimpleIdentifier) { | 219 if (node is SimpleIdentifier) { |
| 210 if (node.inDeclarationContext()) { | 220 if (node.inDeclarationContext()) { |
| 211 return new RefactoringStatus.fatal( | 221 return new RefactoringStatus.fatal( |
| (...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 | 629 |
| 620 _TokenLocalElementVisitor(this.map); | 630 _TokenLocalElementVisitor(this.map); |
| 621 | 631 |
| 622 visitSimpleIdentifier(SimpleIdentifier node) { | 632 visitSimpleIdentifier(SimpleIdentifier node) { |
| 623 Element element = node.staticElement; | 633 Element element = node.staticElement; |
| 624 if (element is LocalVariableElement) { | 634 if (element is LocalVariableElement) { |
| 625 map[node.token] = element; | 635 map[node.token] = element; |
| 626 } | 636 } |
| 627 } | 637 } |
| 628 } | 638 } |
| OLD | NEW |