| 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 if (_isPartOfConstantExpression(rootExpression)) { | 69 if (_isPartOfConstantExpression(rootExpression)) { |
| 70 return "const"; | 70 return "const"; |
| 71 } else { | 71 } else { |
| 72 return "var"; | 72 return "var"; |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 @override | 76 @override |
| 77 Future<RefactoringStatus> checkFinalConditions() { | 77 Future<RefactoringStatus> checkFinalConditions() { |
| 78 RefactoringStatus result = new RefactoringStatus(); | 78 RefactoringStatus result = new RefactoringStatus(); |
| 79 if (excludedVariableNames.contains(name)) { | 79 result.addStatus(checkName()); |
| 80 result.addWarning(format( | |
| 81 "A variable with name '{0}' is already defined in the visible scope.", | |
| 82 name)); | |
| 83 } | |
| 84 return new Future.value(result); | 80 return new Future.value(result); |
| 85 } | 81 } |
| 86 | 82 |
| 87 @override | 83 @override |
| 88 Future<RefactoringStatus> checkInitialConditions() { | 84 Future<RefactoringStatus> checkInitialConditions() { |
| 89 RefactoringStatus result = new RefactoringStatus(); | 85 RefactoringStatus result = new RefactoringStatus(); |
| 90 // selection | 86 // selection |
| 91 result.addStatus(_checkSelection()); | 87 result.addStatus(_checkSelection()); |
| 92 if (result.hasFatalError) { | 88 if (result.hasFatalError) { |
| 93 return new Future.value(result); | 89 return new Future.value(result); |
| 94 } | 90 } |
| 95 // occurrences | 91 // occurrences |
| 96 _prepareOccurrences(); | 92 _prepareOccurrences(); |
| 97 _prepareOffsetsLengths(); | 93 _prepareOffsetsLengths(); |
| 98 // names | 94 // names |
| 99 excludedVariableNames = | 95 excludedVariableNames = |
| 100 utils.findPossibleLocalVariableConflicts(selectionOffset); | 96 utils.findPossibleLocalVariableConflicts(selectionOffset); |
| 101 _prepareNames(); | 97 _prepareNames(); |
| 102 // done | 98 // done |
| 103 return new Future.value(result); | 99 return new Future.value(result); |
| 104 } | 100 } |
| 105 | 101 |
| 106 @override | 102 @override |
| 107 RefactoringStatus checkName() { | 103 RefactoringStatus checkName() { |
| 108 return validateVariableName(name); | 104 RefactoringStatus result = new RefactoringStatus(); |
| 105 result.addStatus(validateVariableName(name)); |
| 106 if (excludedVariableNames.contains(name)) { |
| 107 result.addError( |
| 108 format("The name '{0}' is already used in the scope.", name)); |
| 109 } |
| 110 return result; |
| 109 } | 111 } |
| 110 | 112 |
| 111 @override | 113 @override |
| 112 Future<SourceChange> createChange() { | 114 Future<SourceChange> createChange() { |
| 113 SourceChange change = new SourceChange(refactoringName); | 115 SourceChange change = new SourceChange(refactoringName); |
| 114 // prepare occurrences | 116 // prepare occurrences |
| 115 List<SourceRange> occurrences; | 117 List<SourceRange> occurrences; |
| 116 if (extractAll) { | 118 if (extractAll) { |
| 117 occurrences = this.occurrences; | 119 occurrences = this.occurrences; |
| 118 } else { | 120 } else { |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 678 |
| 677 _TokenLocalElementVisitor(this.map); | 679 _TokenLocalElementVisitor(this.map); |
| 678 | 680 |
| 679 visitSimpleIdentifier(SimpleIdentifier node) { | 681 visitSimpleIdentifier(SimpleIdentifier node) { |
| 680 Element element = node.staticElement; | 682 Element element = node.staticElement; |
| 681 if (element is LocalVariableElement) { | 683 if (element is LocalVariableElement) { |
| 682 map[node.token] = element; | 684 map[node.token] = element; |
| 683 } | 685 } |
| 684 } | 686 } |
| 685 } | 687 } |
| OLD | NEW |