mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
Implement search for PrefixElement.
R=brianwilkerson@google.com BUG= Review URL: https://codereview.chromium.org/2535173004 .
This commit is contained in:
parent
1370b6bb46
commit
7c3932d594
|
@ -60,6 +60,8 @@ class Search {
|
|||
return _searchReferences_Local(element, (n) => n is Block);
|
||||
} else if (kind == ElementKind.PARAMETER) {
|
||||
return _searchReferences_Parameter(element);
|
||||
} else if (kind == ElementKind.PREFIX) {
|
||||
return _searchReferences_Prefix(element);
|
||||
} else if (kind == ElementKind.TYPE_PARAMETER) {
|
||||
return _searchReferences_Local(
|
||||
element, (n) => n.parent is CompilationUnit);
|
||||
|
@ -196,6 +198,27 @@ class Search {
|
|||
}));
|
||||
return results;
|
||||
}
|
||||
|
||||
Future<List<SearchResult>> _searchReferences_Prefix(
|
||||
PrefixElement element) async {
|
||||
// Search only in drivers to which the library with the prefix was added.
|
||||
String path = element.source.fullName;
|
||||
if (!_driver.addedFiles.contains(path)) {
|
||||
return const <SearchResult>[];
|
||||
}
|
||||
|
||||
List<SearchResult> results = <SearchResult>[];
|
||||
LibraryElement libraryElement = element.library;
|
||||
for (CompilationUnitElement unitElement in libraryElement.units) {
|
||||
String unitPath = unitElement.source.fullName;
|
||||
AnalysisResult unitAnalysisResult = await _driver.getResult(unitPath);
|
||||
_LocalReferencesVisitor visitor =
|
||||
new _LocalReferencesVisitor(element, unitElement);
|
||||
unitAnalysisResult.unit.accept(visitor);
|
||||
results.addAll(visitor.results);
|
||||
}
|
||||
return results;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,6 +38,7 @@ class ExpectedResult {
|
|||
result.isResolved == this.isResolved &&
|
||||
result.isQualified == this.isQualified &&
|
||||
result.offset == this.offset &&
|
||||
result.length == this.length &&
|
||||
result.enclosingElement == this.enclosingElement;
|
||||
}
|
||||
|
||||
|
@ -510,6 +511,34 @@ main() {
|
|||
await _verifyReferences(element, expected);
|
||||
}
|
||||
|
||||
test_searchReferences_PrefixElement() async {
|
||||
String partCode = r'''
|
||||
part of my_lib;
|
||||
ppp.Future c;
|
||||
''';
|
||||
provider.newFile(_p('$testProject/my_part.dart'), partCode);
|
||||
await _resolveTestUnit('''
|
||||
library my_lib;
|
||||
import 'dart:async' as ppp;
|
||||
part 'my_part.dart';
|
||||
main() {
|
||||
ppp.Future a;
|
||||
ppp.Stream b;
|
||||
}
|
||||
''');
|
||||
PrefixElement element = _findElementAtString('ppp;');
|
||||
Element a = _findElement('a');
|
||||
Element b = _findElement('b');
|
||||
Element c = findChildElement(testLibraryElement, 'c');
|
||||
var expected = [
|
||||
_expectId(a, SearchResultKind.REFERENCE, 'ppp.Future'),
|
||||
_expectId(b, SearchResultKind.REFERENCE, 'ppp.Stream'),
|
||||
new ExpectedResult(c, SearchResultKind.REFERENCE,
|
||||
partCode.indexOf('ppp.Future c'), 'ppp'.length)
|
||||
];
|
||||
await _verifyReferences(element, expected);
|
||||
}
|
||||
|
||||
test_searchReferences_PropertyAccessorElement_getter() async {
|
||||
await _resolveTestUnit('''
|
||||
class A {
|
||||
|
|
Loading…
Reference in a new issue