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

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.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/correction/util.dart
diff --git a/pkg/analysis_server/lib/src/services/correction/util.dart b/pkg/analysis_server/lib/src/services/correction/util.dart
index f214c9fd26b792398af53a290f8088f0d58e704f..d7382bbc04200722a6d28697167372cdfdb5f8a6 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -12,6 +12,7 @@ import 'package:analysis_server/src/protocol_server.dart'
show doSourceChange_addElementEdit;
import 'package:analysis_server/src/services/correction/source_range.dart';
import 'package:analysis_server/src/services/correction/strings.dart';
+import 'package:analysis_server/src/services/search/element_visitors.dart';
import 'package:analyzer/src/generated/ast.dart';
import 'package:analyzer/src/generated/element.dart';
import 'package:analyzer/src/generated/engine.dart';
@@ -596,6 +597,33 @@ class CorrectionUtils {
new NodeLocator.con1(offset).searchWithin(unit);
/**
+ * Returns names of elements that might conflict with a new local variable
+ * declared at [offset].
+ */
+ Set<String> findPossibleLocalVariableConflicts(int offset) {
+ Set<String> conflicts = new Set<String>();
+ AstNode enclosingNode = findNode(offset);
+ Block enclosingBlock = enclosingNode.getAncestor((node) => node is Block);
+ if (enclosingBlock != null) {
+ SourceRange newRange = rangeStartEnd(offset, 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(newRange)) {
+ conflicts.add(element.displayName);
+ }
+ }
+ return true;
+ });
+ }
+ }
+ return conflicts;
+ }
+
+ /**
* Returns the actual type source of the given [Expression], may be `null`
* if can not be resolved, should be treated as the `dynamic` type.
*/

Powered by Google App Engine
This is Rietveld 408576698