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

Unified Diff: pkg/analysis_server/lib/src/services/correction/util.dart

Issue 1528013004: Issue 25253. Improve collecting names that may conflict with the extracted local variable. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/refactoring/extract_local.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 414765de04d6a61544c05152e96876b9ff700983..33a31052474bfd976e39df83f3b2b15cfc876b56 100644
--- a/pkg/analysis_server/lib/src/services/correction/util.dart
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart
@@ -12,7 +12,6 @@ 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/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/generated/ast.dart';
@@ -668,20 +667,9 @@ class CorrectionUtils {
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;
- });
- }
+ _CollectReferencedUnprefixedNames visitor = new _CollectReferencedUnprefixedNames();
+ enclosingBlock.accept(visitor);
+ return visitor.names;
}
return conflicts;
}
@@ -1437,6 +1425,26 @@ class TokenUtils {
tokens.length == 1 && tokens[0].type == type;
}
+class _CollectReferencedUnprefixedNames extends RecursiveAstVisitor {
+ final Set<String> names = new Set<String>();
+
+ void visitSimpleIdentifier(SimpleIdentifier node) {
+ if (!_isPrefixed(node)) {
+ names.add(node.name);
+ }
+ }
+
+ static bool _isPrefixed(SimpleIdentifier node) {
+ AstNode parent = node.parent;
+ return parent is ConstructorName && parent.name == node ||
+ parent is MethodInvocation &&
+ parent.methodName == node &&
+ parent.realTarget != null ||
+ parent is PrefixedIdentifier && parent.identifier == node ||
+ parent is PropertyAccess && parent.target == node;
+ }
+}
+
/**
* A container with a source and its precedence.
*/
« no previous file with comments | « no previous file | pkg/analysis_server/lib/src/services/refactoring/extract_local.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698