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

Unified Diff: pkg/analyzer/lib/src/dart/analysis/search.dart

Issue 2572603003: Implement SearchEngine.searchTopLevelDeclarations() for the new driver. (Closed)
Patch Set: Created 4 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
Index: pkg/analyzer/lib/src/dart/analysis/search.dart
diff --git a/pkg/analyzer/lib/src/dart/analysis/search.dart b/pkg/analyzer/lib/src/dart/analysis/search.dart
index 1c569ed263e94a5fa64b72762b237203c49d378d..59a1a63dda8b575b6f202e4d218a06e5a377066b 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -91,6 +91,31 @@ class Search {
return results;
}
+ /**
+ * Returns top-level elements with names matching the given [regExp].
+ */
+ Future<List<Element>> topLevelElements(RegExp regExp) async {
+ List<Element> elements = <Element>[];
+
+ void addElement(Element element) {
+ if (!element.isSynthetic && regExp.hasMatch(element.displayName)) {
+ elements.add(element);
+ }
+ }
+
+ for (FileState file in _driver.fsState.knownFiles) {
+ CompilationUnitElement unitElement =
+ await _driver.getUnitElement(file.path);
+ unitElement.accessors.forEach(addElement);
+ unitElement.enums.forEach(addElement);
+ unitElement.functions.forEach(addElement);
+ unitElement.functionTypeAliases.forEach(addElement);
+ unitElement.topLevelVariables.forEach(addElement);
+ unitElement.types.forEach(addElement);
+ }
+ return elements;
+ }
+
Future<Null> _addResults(List<SearchResult> results, Element element,
Map<IndexRelationKind, SearchResultKind> relationToResultKind) async {
// Prepare the element name.

Powered by Google App Engine
This is Rietveld 408576698