Index: pkg/analysis_server/lib/src/search/search_result.dart |
diff --git a/pkg/analysis_server/lib/src/search/search_result.dart b/pkg/analysis_server/lib/src/search/search_result.dart |
index 158356c00eb22e5e8ab30b571f0996a7c2b33ba0..7e08d5f3c99346dade2ef62551b952158095fc6f 100644 |
--- a/pkg/analysis_server/lib/src/search/search_result.dart |
+++ b/pkg/analysis_server/lib/src/search/search_result.dart |
@@ -4,154 +4,27 @@ |
library search.search_result; |
-import 'package:analysis_server/src/computer/element.dart'; |
-import 'package:analysis_server/src/constants.dart'; |
-import 'package:analysis_server/src/services/json.dart'; |
+import 'package:analysis_server/src/protocol2.dart'; |
import 'package:analysis_server/src/services/search/search_engine.dart'; |
import 'package:analyzer/src/generated/element.dart' as engine; |
-/** |
- * A single result from a search request. |
- */ |
-class SearchResult implements HasToJson { |
- /** |
- * The kind of element that was found or the kind of reference that was found. |
- */ |
- final SearchResultKind kind; |
- |
- /** |
- * Is `true` if the result is a potential match but cannot be confirmed to be |
- * a match. |
- * |
- * For example, if all references to a method `m` defined in some class were |
- * requested, and a reference to a method `m` from an unknown class were |
- * found, it would be marked as being a potential match. |
- */ |
- final bool isPotential; |
- |
- /** |
- * The location of the code that matched the search criteria. |
- */ |
- final Location location; |
- |
- /** |
- * The elements that contain the result, starting with the most immediately |
- * enclosing ancestor and ending with the library. |
- */ |
- final List<Element> path; |
- |
- SearchResult(this.kind, this.isPotential, this.location, this.path); |
- |
- factory SearchResult.fromJson(Map<String, Object> map) { |
- SearchResultKind kind = new SearchResultKind.fromName(map[KIND]); |
- bool isPotential = map[IS_POTENTIAL]; |
- Location location = new Location.fromJson(map[LOCATION]); |
- List<Map<String, Object>> pathJson = map[PATH]; |
- List<Element> path = pathJson.map((json) { |
- return new Element.fromJson(json); |
- }).toList(); |
- return new SearchResult(kind, isPotential, location, path); |
- } |
- |
- factory SearchResult.fromMatch(SearchMatch match) { |
- SearchResultKind kind = new SearchResultKind.fromEngine(match.kind); |
- Location location = |
- new Location.fromOffset( |
- match.element, |
- match.sourceRange.offset, |
- match.sourceRange.length); |
- List<Element> path = _computePath(match.element); |
- return new SearchResult(kind, !match.isResolved, location, path); |
- } |
- |
- Map<String, Object> toJson() { |
- return { |
- KIND: kind.name, |
- IS_POTENTIAL: isPotential, |
- LOCATION: location.toJson(), |
- PATH: path.map(Element.asJson).toList() |
- }; |
- } |
- |
- @override |
- String toString() => toJson().toString(); |
- |
- static Map<String, Object> asJson(SearchResult result) { |
- return result.toJson(); |
- } |
- |
- static List<Element> _computePath(engine.Element element) { |
- List<Element> path = <Element>[]; |
- while (element != null) { |
- path.add(new Element.fromEngine(element)); |
- element = element.enclosingElement; |
- } |
- return path; |
- } |
+SearchResult searchResultFromMatch(SearchMatch match) { |
+ SearchResultKind kind = new SearchResultKind.fromEngine(match.kind); |
+ Location location = |
+ new Location.fromOffset( |
+ match.element, |
+ match.sourceRange.offset, |
+ match.sourceRange.length); |
+ List<Element> path = _computePath(match.element); |
+ return new SearchResult(location, kind, !match.isResolved, path); |
} |
- |
-/** |
- * An enumeration of the kinds of search results returned by the search domain. |
- */ |
-class SearchResultKind { |
- static const DECLARATION = const SearchResultKind('DECLARATION'); |
- static const READ = const SearchResultKind('READ'); |
- static const READ_WRITE = const SearchResultKind('READ_WRITE'); |
- static const WRITE = const SearchResultKind('WRITE'); |
- static const INVOCATION = const SearchResultKind('INVOCATION'); |
- static const REFERENCE = const SearchResultKind('REFERENCE'); |
- static const UNKNOWN = const SearchResultKind('UNKNOWN'); |
- |
- final String name; |
- |
- const SearchResultKind(this.name); |
- |
- factory SearchResultKind.fromEngine(MatchKind kind) { |
- if (kind == MatchKind.DECLARATION) { |
- return DECLARATION; |
- } |
- if (kind == MatchKind.READ) { |
- return READ; |
- } |
- if (kind == MatchKind.READ_WRITE) { |
- return READ_WRITE; |
- } |
- if (kind == MatchKind.WRITE) { |
- return WRITE; |
- } |
- if (kind == MatchKind.INVOCATION) { |
- return INVOCATION; |
- } |
- if (kind == MatchKind.REFERENCE) { |
- return REFERENCE; |
- } |
- return UNKNOWN; |
+List<Element> _computePath(engine.Element element) { |
+ List<Element> path = <Element>[]; |
+ while (element != null) { |
+ path.add(new Element.fromEngine(element)); |
+ element = element.enclosingElement; |
} |
- |
- factory SearchResultKind.fromName(String name) { |
- if (name == DECLARATION.name) { |
- return DECLARATION; |
- } |
- if (name == READ.name) { |
- return READ; |
- } |
- if (name == READ_WRITE.name) { |
- return READ_WRITE; |
- } |
- if (name == WRITE.name) { |
- return WRITE; |
- } |
- if (name == INVOCATION.name) { |
- return INVOCATION; |
- } |
- if (name == REFERENCE.name) { |
- return REFERENCE; |
- } |
- return UNKNOWN; |
- } |
- |
- @override |
- String toString() => name; |
+ return path; |
} |