| 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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 225 } |
| 226 // get covering node | 226 // get covering node |
| 227 AstNode coveringNode = | 227 AstNode coveringNode = |
| 228 new NodeLocator(selectionRange.offset, selectionRange.end) | 228 new NodeLocator(selectionRange.offset, selectionRange.end) |
| 229 .searchWithin(unit); | 229 .searchWithin(unit); |
| 230 // compute covering expressions | 230 // compute covering expressions |
| 231 for (AstNode node = coveringNode; | 231 for (AstNode node = coveringNode; |
| 232 node is Expression || node is ArgumentList; | 232 node is Expression || node is ArgumentList; |
| 233 node = node.parent) { | 233 node = node.parent) { |
| 234 AstNode parent = node.parent; | 234 AstNode parent = node.parent; |
| 235 // stop at void method invocations |
| 236 if (node is MethodInvocation) { |
| 237 MethodInvocation invocation = node; |
| 238 Element element = invocation.methodName.bestElement; |
| 239 if (element is ExecutableElement && |
| 240 element.returnType != null && |
| 241 element.returnType.isVoid) { |
| 242 if (rootExpression == null) { |
| 243 return new RefactoringStatus.fatal( |
| 244 'Cannot extract the void expression.', |
| 245 newLocation_fromNode(node)); |
| 246 } |
| 247 break; |
| 248 } |
| 249 } |
| 235 // skip ArgumentList | 250 // skip ArgumentList |
| 236 if (node is ArgumentList) { | 251 if (node is ArgumentList) { |
| 237 continue; | 252 continue; |
| 238 } | 253 } |
| 239 // skip AssignmentExpression | 254 // skip AssignmentExpression |
| 240 if (node is AssignmentExpression) { | 255 if (node is AssignmentExpression) { |
| 241 continue; | 256 continue; |
| 242 } | 257 } |
| 243 // cannot extract the name part of a property access | 258 // cannot extract the name part of a property access |
| 244 if (parent is PrefixedIdentifier && parent.identifier == node || | 259 if (parent is PrefixedIdentifier && parent.identifier == node || |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 676 |
| 662 _TokenLocalElementVisitor(this.map); | 677 _TokenLocalElementVisitor(this.map); |
| 663 | 678 |
| 664 visitSimpleIdentifier(SimpleIdentifier node) { | 679 visitSimpleIdentifier(SimpleIdentifier node) { |
| 665 Element element = node.staticElement; | 680 Element element = node.staticElement; |
| 666 if (element is LocalVariableElement) { | 681 if (element is LocalVariableElement) { |
| 667 map[node.token] = element; | 682 map[node.token] = element; |
| 668 } | 683 } |
| 669 } | 684 } |
| 670 } | 685 } |
| OLD | NEW |