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 2e73715e74333551b069e6ef61ec3a653912cef7..63533761ad71bb8d76975a5e3bedd0ab7e4650fc 100644 |
--- a/pkg/analysis_server/lib/src/services/correction/util.dart |
+++ b/pkg/analysis_server/lib/src/services/correction/util.dart |
@@ -218,6 +218,15 @@ String getDefaultValueCode(DartType type) { |
} |
/** |
+ * Return all [LocalElement]s defined in the given [node]. |
+ */ |
+List<LocalElement> getDefinedLocalElements(AstNode node) { |
+ var collector = new _LocalElementsCollector(); |
+ node.accept(collector); |
+ return collector.elements; |
+} |
+ |
+/** |
* Return the name of the [Element] kind. |
*/ |
String getElementKindName(Element element) { |
@@ -1537,3 +1546,20 @@ class _InvertedCondition { |
static _InvertedCondition _simple(String source) => |
new _InvertedCondition(2147483647, source); |
} |
+ |
+/** |
+ * Visitor that collects defined [LocalElement]s. |
+ */ |
+class _LocalElementsCollector extends RecursiveAstVisitor { |
+ final elements = <LocalElement>[]; |
+ |
+ @override |
+ visitSimpleIdentifier(SimpleIdentifier node) { |
+ if (node.inDeclarationContext()) { |
+ Element element = node.staticElement; |
+ if (element is LocalElement) { |
+ elements.add(element); |
+ } |
+ } |
+ } |
+} |