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

Unified Diff: pkg/analysis_server/lib/src/services/search/search_engine_internal2.dart

Issue 2521363003: Implement SearchEngine for the new driver. (Closed)
Patch Set: Created 4 years, 1 month 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/search/search_engine_internal2.dart
diff --git a/pkg/analysis_server/lib/src/services/search/search_engine_internal2.dart b/pkg/analysis_server/lib/src/services/search/search_engine_internal2.dart
new file mode 100644
index 0000000000000000000000000000000000000000..72cd49496571f0517c9bfd36d9e8bdc610f718dd
--- /dev/null
+++ b/pkg/analysis_server/lib/src/services/search/search_engine_internal2.dart
@@ -0,0 +1,149 @@
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'dart:async';
+
+import 'package:analysis_server/src/services/search/search_engine.dart';
+import 'package:analyzer/dart/element/element.dart';
+import 'package:analyzer/src/dart/analysis/driver.dart';
+import 'package:analyzer/src/dart/analysis/search.dart';
+import 'package:analyzer/src/generated/source.dart' show Source, SourceRange;
+
+/**
+ * A [SearchEngine] implementation.
+ */
+class SearchEngineImpl2 implements SearchEngine {
+ final Iterable<AnalysisDriver> _drivers;
+
+ SearchEngineImpl2(this._drivers);
+
+ @override
+ Future<List<SearchMatch>> searchAllSubtypes(ClassElement type) async {
+ // TODO(scheglov) implement
+ return [];
+ }
+
+ @override
+ Future<List<SearchMatch>> searchMemberDeclarations(String name) async {
+ // TODO(scheglov) implement
+ return [];
+ }
+
+ @override
+ Future<List<SearchMatch>> searchMemberReferences(String name) async {
+ // TODO(scheglov) implement
+ return [];
+ }
+
+ @override
+ Future<List<SearchMatch>> searchReferences(Element element) async {
+ List<SearchResult> allResults = [];
+ for (AnalysisDriver driver in _drivers) {
+ List<SearchResult> results = await driver.search.references(element);
+ allResults.addAll(results);
+ }
+ return allResults.map(_SearchMatch.forSearchResult).toList();
+ }
+
+ @override
+ Future<List<SearchMatch>> searchSubtypes(ClassElement type) async {
+ // TODO(scheglov) implement
+ return [];
+ }
+
+ @override
+ Future<List<SearchMatch>> searchTopLevelDeclarations(String pattern) async {
+ // TODO(scheglov) implement
+ return [];
+ }
+}
+
+class _SearchMatch implements SearchMatch {
+ @override
+ final String file;
+
+ @override
+ final Source librarySource;
+
+ @override
+ final Source unitSource;
+
+ @override
+ final LibraryElement libraryElement;
+
+ @override
+ final Element element;
+
+ @override
+ final bool isResolved;
+
+ @override
+ final bool isQualified;
+
+ @override
+ final MatchKind kind;
+
+ @override
+ final SourceRange sourceRange;
+
+ _SearchMatch(
+ this.file,
+ this.librarySource,
+ this.unitSource,
+ this.libraryElement,
+ this.element,
+ this.isResolved,
+ this.isQualified,
+ this.kind,
+ this.sourceRange);
+
+ @override
+ String toString() {
+ StringBuffer buffer = new StringBuffer();
+ buffer.write("SearchMatch(kind=");
+ buffer.write(kind);
+ buffer.write(", libraryUri=");
+ buffer.write(librarySource.uri);
+ buffer.write(", unitUri=");
+ buffer.write(unitSource.uri);
+ buffer.write(", range=");
+ buffer.write(sourceRange);
+ buffer.write(", isResolved=");
+ buffer.write(isResolved);
+ buffer.write(", isQualified=");
+ buffer.write(isQualified);
+ buffer.write(")");
+ return buffer.toString();
+ }
+
+ static _SearchMatch forSearchResult(SearchResult result) {
+ Element enclosingElement = result.enclosingElement;
+ return new _SearchMatch(
+ enclosingElement.source.fullName,
+ enclosingElement.librarySource,
+ enclosingElement.source,
+ enclosingElement.library,
+ enclosingElement,
+ result.isResolved,
+ result.isQualified,
+ toMatchKind(result.kind),
+ new SourceRange(result.offset, result.length));
+ }
+
+ static MatchKind toMatchKind(SearchResultKind kind) {
+ if (kind == SearchResultKind.READ) {
+ return MatchKind.READ;
+ }
+ if (kind == SearchResultKind.READ_WRITE) {
+ return MatchKind.READ_WRITE;
+ }
+ if (kind == SearchResultKind.WRITE) {
+ return MatchKind.WRITE;
+ }
+ if (kind == SearchResultKind.INVOCATION) {
+ return MatchKind.INVOCATION;
+ }
+ return MatchKind.REFERENCE;
+ }
+}
« no previous file with comments | « pkg/analysis_server/lib/src/search/search_domain.dart ('k') | pkg/analyzer/lib/src/dart/analysis/search.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698