| 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 for (AstNode node = coveringNode; node is Expression; node = node.parent) { | 200 for (AstNode node = coveringNode; node is Expression; node = node.parent) { |
| 201 AstNode parent = node.parent; | 201 AstNode parent = node.parent; |
| 202 // cannot extract the name part of a property access | 202 // cannot extract the name part of a property access |
| 203 if (parent is PrefixedIdentifier && parent.identifier == node || | 203 if (parent is PrefixedIdentifier && parent.identifier == node || |
| 204 parent is PropertyAccess && parent.propertyName == node) { | 204 parent is PropertyAccess && parent.propertyName == node) { |
| 205 continue; | 205 continue; |
| 206 } | 206 } |
| 207 // fatal selection problems | 207 // fatal selection problems |
| 208 if (coveringExpressionOffsets.isEmpty) { | 208 if (coveringExpressionOffsets.isEmpty) { |
| 209 if (node is SimpleIdentifier) { | 209 if (node is SimpleIdentifier) { |
| 210 Element element = node.bestElement; | |
| 211 if (element is FunctionElement || element is MethodElement) { | |
| 212 return new RefactoringStatus.fatal( | |
| 213 'Cannot extract a single method name.', | |
| 214 newLocation_fromNode(node)); | |
| 215 } | |
| 216 if (node.inDeclarationContext()) { | 210 if (node.inDeclarationContext()) { |
| 217 return new RefactoringStatus.fatal( | 211 return new RefactoringStatus.fatal( |
| 218 'Cannot extract the name part of a declaration.', | 212 'Cannot extract the name part of a declaration.', |
| 219 newLocation_fromNode(node)); | 213 newLocation_fromNode(node)); |
| 220 } | 214 } |
| 215 Element element = node.bestElement; |
| 216 if (element is FunctionElement || element is MethodElement) { |
| 217 continue; |
| 218 } |
| 221 } | 219 } |
| 222 if (parent is AssignmentExpression && parent.leftHandSide == node) { | 220 if (parent is AssignmentExpression && parent.leftHandSide == node) { |
| 223 return new RefactoringStatus.fatal( | 221 return new RefactoringStatus.fatal( |
| 224 'Cannot extract the left-hand side of an assignment.', | 222 'Cannot extract the left-hand side of an assignment.', |
| 225 newLocation_fromNode(node)); | 223 newLocation_fromNode(node)); |
| 226 } | 224 } |
| 227 } | 225 } |
| 228 // set selected expression | 226 // set selected expression |
| 229 if (coveringExpressionOffsets.isEmpty) { | 227 if (coveringExpressionOffsets.isEmpty) { |
| 230 rootExpression = node; | 228 rootExpression = node; |
| (...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 | 619 |
| 622 _TokenLocalElementVisitor(this.map); | 620 _TokenLocalElementVisitor(this.map); |
| 623 | 621 |
| 624 visitSimpleIdentifier(SimpleIdentifier node) { | 622 visitSimpleIdentifier(SimpleIdentifier node) { |
| 625 Element element = node.staticElement; | 623 Element element = node.staticElement; |
| 626 if (element is LocalVariableElement) { | 624 if (element is LocalVariableElement) { |
| 627 map[node.token] = element; | 625 map[node.token] = element; |
| 628 } | 626 } |
| 629 } | 627 } |
| 630 } | 628 } |
| OLD | NEW |