Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(463)

Unified Diff: pkg/analysis_server/lib/src/services/refactoring/extract_local.dart

Issue 1012623002: Issue 22833. Quick Assist to convert for-each into for-index. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
diff --git a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
index e01942c8e05de8777498f49b48d66eb2a912d35c..81676c1e6ab0ead1c62cb912f3bce55e2c983748 100644
--- a/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
+++ b/pkg/analysis_server/lib/src/services/refactoring/extract_local.dart
@@ -51,7 +51,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
String stringLiteralPart;
final List<SourceRange> occurrences = <SourceRange>[];
final Map<Element, int> elementIds = <Element, int>{};
- final Set<String> excludedVariableNames = new Set<String>();
+ Set<String> excludedVariableNames = new Set<String>();
ExtractLocalRefactoringImpl(
this.unit, this.selectionOffset, this.selectionLength) {
@@ -94,7 +94,8 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
_prepareOccurrences();
_prepareOffsetsLengths();
// names
- _prepareExcludedNames();
+ excludedVariableNames =
+ utils.findPossibleLocalVariableConflicts(selectionOffset);
_prepareNames();
// done
return new Future.value(result);
@@ -371,31 +372,6 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
return false;
}
- void _prepareExcludedNames() {
- excludedVariableNames.clear();
- AstNode enclosingNode =
- new NodeLocator.con1(selectionOffset).searchWithin(unit);
- Block enclosingBlock = enclosingNode.getAncestor((node) => node is Block);
- if (enclosingBlock != null) {
- SourceRange newVariableVisibleRange =
- rangeStartEnd(selectionRange, enclosingBlock.end);
- ExecutableElement enclosingExecutable =
- getEnclosingExecutableElement(enclosingNode);
- if (enclosingExecutable != null) {
- visitChildren(enclosingExecutable, (Element element) {
- if (element is LocalElement) {
- SourceRange elementRange = element.visibleRange;
- if (elementRange != null &&
- elementRange.intersects(newVariableVisibleRange)) {
- excludedVariableNames.add(element.displayName);
- }
- }
- return true;
- });
- }
- }
- }
-
void _prepareNames() {
names.clear();
if (stringLiteralPart != null) {

Powered by Google App Engine
This is Rietveld 408576698