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

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

Issue 2956193003: Implement search for direct subtypes in a single AnalysisDriver. (Closed)
Patch Set: Created 3 years, 6 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/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 6bb75be6fc6449924891d740760ccd1920aef659..c669fae9a7661523b4b41dfb74464cd1699bdcd1 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -120,6 +120,47 @@ class Search {
}
/**
+ * Return direct [SubtypeResult]s for either the [type] or [subtype].
+ */
+ Future<List<SubtypeResult>> subtypes(
+ {ClassElement type, SubtypeResult subtype}) async {
+ String name;
+ String id;
+ if (type != null) {
+ name = type.name;
+ id = type.librarySource.uri.toString() +
+ ';' +
+ type.source.uri.toString() +
+ ';' +
+ name;
+ } else {
+ name = subtype.name;
+ id = subtype.id;
+ }
+
+ List<SubtypeResult> results = [];
+ for (String path in _driver.addedFiles) {
+ FileState file = _driver.fsState.getFileForPath(path);
+ if (file.subtypedNames.contains(name)) {
+ AnalysisDriverResolvedUnit unit = _driver.getResolvedUnitObject(file);
+ if (unit != null) {
+ for (AnalysisDriverSubtype subtype in unit.index.subtypes) {
+ if (subtype.supertypes.contains(id)) {
+ FileState library = file.isPart ? file.library : file;
+ results.add(new SubtypeResult(
+ library.uriStr + ';' + file.uriStr + ';' + subtype.name,
+ subtype.name,
+ subtype.members));
+ }
+ }
+ }
+ }
+ }
+
+ return results;
+ }
+
+ /**
* Returns top-level elements with names matching the given [regExp].
*/
Future<List<Element>> topLevelElements(RegExp regExp) async {
@@ -499,6 +540,28 @@ class SearchResult {
enum SearchResultKind { READ, READ_WRITE, WRITE, INVOCATION, REFERENCE }
/**
+ * A single subtype of a type.
+ */
+class SubtypeResult {
+ /**
+ * The identifier of the subtype.
+ */
+ final String id;
+
+ /**
+ * The name of the subtype.
+ */
+ final String name;
+
+ /**
+ * The names of members declared in the class.
+ */
+ final List<String> members;
+
+ SubtypeResult(this.id, this.name, this.members);
+}
+
+/**
* A visitor that finds the deep-most [Element] that contains the [offset].
*/
class _ContainingElementFinder extends GeneralizingElementVisitor {
« no previous file with comments | « pkg/analyzer/lib/src/dart/analysis/driver.dart ('k') | pkg/analyzer/test/src/dart/analysis/search_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698