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

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

Issue 2521913004: Deoptimize Search - request a new resolved unit for local search. (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
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/base.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 e28a5b6dd5ba76d02ecf69aa933232c975b15938..1dfe7b3600bfc871370795e51bb8a8d6bc4a4cd4 100644
--- a/pkg/analyzer/lib/src/dart/analysis/search.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/search.dart
@@ -21,47 +21,46 @@ class Search {
Search(this._driver);
/**
- * Returns references to the element at the given [offset] in the file with
- * the given [path].
+ * Returns references to the [element].
*/
- Future<List<SearchResult>> references(String path, int offset) async {
- // Search only in added files.
- if (!_driver.addedFiles.contains(path)) {
+ Future<List<SearchResult>> references(Element element) async {
+ if (element == null) {
return const <SearchResult>[];
}
+ ElementKind kind = element.kind;
+ if (kind == ElementKind.LABEL || kind == ElementKind.LOCAL_VARIABLE) {
+ return _searchReferences_Local(element, (n) => n is Block);
+ }
+ // TODO(scheglov) support other kinds
+ return const <SearchResult>[];
+ }
+
+ Future<List<SearchResult>> _searchReferences_Local(
+ Element element, bool isRootNode(AstNode n)) async {
+ String path = element.source.fullName;
+
+ // Prepare the unit.
AnalysisResult analysisResult = await _driver.getResult(path);
CompilationUnit unit = analysisResult.unit;
-
- // Prepare the node.
- AstNode node = new NodeLocator(offset).searchWithin(unit);
- if (node == null) {
+ if (unit == null) {
return const <SearchResult>[];
}
- // Prepare the element.
- Element element = ElementLocator.locate(node);
- if (element == null) {
+ // Prepare the node.
+ AstNode node = new NodeLocator(element.nameOffset).searchWithin(unit);
+ if (node == null) {
return const <SearchResult>[];
}
- ElementKind kind = element.kind;
- if (kind == ElementKind.LABEL || kind == ElementKind.LOCAL_VARIABLE) {
- Block block = node.getAncestor((n) => n is Block);
- return _searchReferences_Local(element, unit.element, block);
- }
- // TODO(scheglov) support other kinds
- return [];
- }
+ // Prepare the enclosing node.
+ AstNode enclosingNode = node.getAncestor(isRootNode);
- Future<List<SearchResult>> _searchReferences_Local(
- Element element,
- CompilationUnitElement enclosingUnitElement,
- AstNode enclosingNode) async {
+ // Find the matches.
_LocalReferencesVisitor visitor =
- new _LocalReferencesVisitor(element, enclosingUnitElement);
- enclosingNode?.accept(visitor);
- return visitor.matches;
+ new _LocalReferencesVisitor(element, unit.element);
+ enclosingNode.accept(visitor);
+ return visitor.results;
}
}
@@ -159,7 +158,7 @@ class _ContainingElementFinder extends GeneralizingElementVisitor {
* type parameters, import prefixes.
*/
class _LocalReferencesVisitor extends RecursiveAstVisitor {
- final List<SearchResult> matches = <SearchResult>[];
+ final List<SearchResult> results = <SearchResult>[];
final Element element;
final CompilationUnitElement enclosingUnitElement;
@@ -193,15 +192,15 @@ class _LocalReferencesVisitor extends RecursiveAstVisitor {
kind = SearchResultKind.WRITE;
}
}
- _addMatch(node, kind);
+ _addResult(node, kind);
}
}
- void _addMatch(AstNode node, SearchResultKind kind) {
+ void _addResult(AstNode node, SearchResultKind kind) {
bool isQualified = node.parent is Label;
var finder = new _ContainingElementFinder(node.offset);
enclosingUnitElement.accept(finder);
- matches.add(new SearchResult._(element, finder.containingElement, kind,
+ results.add(new SearchResult._(element, finder.containingElement, kind,
node.offset, node.length, true, isQualified));
}
}
« no previous file with comments | « no previous file | pkg/analyzer/test/src/dart/analysis/base.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698