mirror of
https://github.com/dart-lang/sdk
synced 2024-09-15 21:10:22 +00:00
Restore sync file methods in AnalysisSession.
There are clients, like `built_value` that cannot be updated. Change-Id: I27371018039f22cd7ca2cb82b30ec33469aa6e4e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/238002 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Nate Bosch <nbosch@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
b732254fe6
commit
3d69c3c0c4
|
@ -420,7 +420,7 @@ abstract class AbstractAnalysisServer {
|
|||
return null;
|
||||
}
|
||||
|
||||
var result = await session.getParsedUnit2(path);
|
||||
var result = session.getParsedUnit(path);
|
||||
return result is ParsedUnitResult ? result : null;
|
||||
}
|
||||
|
||||
|
|
|
@ -35,8 +35,8 @@ class SortMembersCommandHandler extends SimpleEditCommandHandler {
|
|||
final path = arguments.single as String;
|
||||
final docIdentifier = server.getVersionedDocumentIdentifier(path);
|
||||
|
||||
var driver = server.getAnalysisDriver(path);
|
||||
final result = await driver?.parseFile(path);
|
||||
var session = await server.getAnalysisSession(path);
|
||||
final result = session?.getParsedUnit(path);
|
||||
|
||||
if (cancellationToken.isCancellationRequested) {
|
||||
return error(ErrorCodes.RequestCancelled, 'Request was cancelled');
|
||||
|
|
|
@ -270,7 +270,7 @@ class DefinitionHandler extends MessageHandler<TextDocumentPositionParams,
|
|||
return null;
|
||||
}
|
||||
|
||||
var parsedLibrary = await session.getParsedLibrary2(libraryPath);
|
||||
var parsedLibrary = session.getParsedLibrary(libraryPath);
|
||||
if (parsedLibrary is! ParsedLibraryResult) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ class RenameImportRefactoringImpl extends RenameRefactoringImpl {
|
|||
Future<ImportDirective?> _findNode() async {
|
||||
var library = element.library;
|
||||
var path = library.source.fullName;
|
||||
var unitResult = await session.getParsedUnit2(path);
|
||||
var unitResult = session.getParsedUnit(path);
|
||||
if (unitResult is! ParsedUnitResult) {
|
||||
return null;
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class RenameImportRefactoringImpl extends RenameRefactoringImpl {
|
|||
SourceReference reference,
|
||||
) async {
|
||||
var source = reference.element.source!;
|
||||
var unitResult = await session.getParsedUnit2(source.fullName);
|
||||
var unitResult = session.getParsedUnit(source.fullName);
|
||||
if (unitResult is! ParsedUnitResult) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -23,10 +23,10 @@ void main() {
|
|||
var contextCollection = AnalysisContextCollection(
|
||||
includedPaths: [fixFilePath],
|
||||
);
|
||||
var parseResult = await contextCollection
|
||||
var parseResult = contextCollection
|
||||
.contextFor(fixFilePath)
|
||||
.currentSession
|
||||
.getParsedUnit2(fixFilePath) as ParsedUnitResult;
|
||||
.getParsedUnit(fixFilePath) as ParsedUnitResult;
|
||||
|
||||
if (parseResult.errors.isNotEmpty) {
|
||||
throw Exception(parseResult.errors);
|
||||
|
|
|
@ -1512,8 +1512,7 @@ class C {} // C
|
|||
|
||||
Future<void> _parseTestUnit(String code) async {
|
||||
addTestSource(code);
|
||||
var result =
|
||||
await (await session).getParsedUnit2(testFile) as ParsedUnitResult;
|
||||
var result = (await session).getParsedUnit(testFile) as ParsedUnitResult;
|
||||
lineInfo = result.lineInfo;
|
||||
testUnit = result.unit;
|
||||
}
|
||||
|
|
|
@ -68,7 +68,7 @@ Future<void> buildTestsIn(AnalysisSession session, String testDirPath,
|
|||
var path = child.path;
|
||||
var relativePath = pathContext.relative(path, from: testDirPath);
|
||||
|
||||
var result = await session.getParsedUnit2(path);
|
||||
var result = session.getParsedUnit(path);
|
||||
if (result is! ParsedUnitResult) {
|
||||
fail('Could not parse $path');
|
||||
}
|
||||
|
|
|
@ -143,7 +143,7 @@ void buildTestsIn(AnalysisSession session, String testDirPath,
|
|||
}
|
||||
var relativePath = pathContext.relative(path, from: testDirPath);
|
||||
test(relativePath, () async {
|
||||
var result = await session.getParsedUnit2(path);
|
||||
var result = session.getParsedUnit(path);
|
||||
if (result is! ParsedUnitResult) {
|
||||
fail('Could not parse $path');
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ void buildTestsIn(AnalysisSession session, String testDirPath,
|
|||
}
|
||||
var relativePath = pathContext.relative(path, from: testDirPath);
|
||||
test(relativePath, () async {
|
||||
var result = await session.getParsedUnit2(path);
|
||||
var result = session.getParsedUnit(path);
|
||||
if (result is! ParsedUnitResult) {
|
||||
fail('Could not parse $path');
|
||||
}
|
||||
|
|
|
@ -1,12 +1,5 @@
|
|||
## 3.4.0-dev
|
||||
* Deprecated synchronous `getFile`, `getParsedLibrary`, `getParsedLibraryByElement`,
|
||||
`getParsedUnit` from `AnalysisSession`. Use corresponding `getXyz2` asynchronous
|
||||
methods instead. This change is necessary for the future work on macros.
|
||||
* Deprecated `Resource.parent2`, use `parent` instead.
|
||||
* Deprecated `AnalysisDriver.getFileSync`, use `getFile` instead.
|
||||
* Deprecated `AnalysisDriver.getParsedLibrary`, use `getParsedLibrary2` instead.
|
||||
* Deprecated `AnalysisDriver.getParsedLibraryByUri`, use `getParsedLibraryByUri2` instead.
|
||||
* Deprecated `AnalysisDriver.parseFileSync`, use `parseFile` instead.
|
||||
* Deprecated `astFactory`, clients should not create AST nodes manually.
|
||||
* Changed `CompilationUnit.lineInfo` to be non-nullable.
|
||||
* Changed `CompilationUnitElement.lineInfo` to be non-nullable.
|
||||
|
|
|
@ -55,7 +55,7 @@ the AST:
|
|||
|
||||
```dart
|
||||
void processFile(AnalysisSession session, String path) async {
|
||||
var result = await session.getParsedUnit2(path);
|
||||
var result = session.getParsedUnit(path);
|
||||
if (result is ParsedUnitResult) {
|
||||
CompilationUnit unit = result.unit;
|
||||
}
|
||||
|
|
|
@ -39,46 +39,24 @@ abstract class AnalysisSession {
|
|||
|
||||
/// Return information about the file at the given absolute, normalized
|
||||
/// [path].
|
||||
@Deprecated('Use getFile2() instead')
|
||||
SomeFileResult getFile(String path);
|
||||
|
||||
/// Return information about the file at the given absolute, normalized
|
||||
/// [path].
|
||||
Future<SomeFileResult> getFile2(String path);
|
||||
|
||||
/// Return a future that will complete with information about the library
|
||||
/// element representing the library with the given [uri].
|
||||
Future<SomeLibraryElementResult> getLibraryByUri(String uri);
|
||||
|
||||
/// Return information about the results of parsing units of the library file
|
||||
/// with the given absolute, normalized [path].
|
||||
@Deprecated('Use getParsedLibrary2() instead')
|
||||
SomeParsedLibraryResult getParsedLibrary(String path);
|
||||
|
||||
/// Return information about the results of parsing units of the library file
|
||||
/// with the given absolute, normalized [path].
|
||||
Future<SomeParsedLibraryResult> getParsedLibrary2(String path);
|
||||
|
||||
/// Return information about the results of parsing units of the library file
|
||||
/// with the given library [element].
|
||||
@Deprecated('Use getParsedLibraryByElement2() instead')
|
||||
SomeParsedLibraryResult getParsedLibraryByElement(LibraryElement element);
|
||||
|
||||
/// Return information about the results of parsing units of the library file
|
||||
/// with the given library [element].
|
||||
Future<SomeParsedLibraryResult> getParsedLibraryByElement2(
|
||||
LibraryElement element,
|
||||
);
|
||||
|
||||
/// Return information about the results of parsing the file with the given
|
||||
/// absolute, normalized [path].
|
||||
@Deprecated('Use getParsedUnit2() instead')
|
||||
SomeParsedUnitResult getParsedUnit(String path);
|
||||
|
||||
/// Return information about the results of parsing the file with the given
|
||||
/// absolute, normalized [path].
|
||||
Future<SomeParsedUnitResult> getParsedUnit2(String path);
|
||||
|
||||
/// Return a future that will complete with information about the results of
|
||||
/// resolving all of the files in the library with the given absolute,
|
||||
/// normalized [path].
|
||||
|
|
|
@ -643,19 +643,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
return getErrors(path);
|
||||
}
|
||||
|
||||
/// Return the [FileResult] for the Dart file with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
Future<SomeFileResult> getFile(String path) async {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
}
|
||||
|
||||
FileState file = _fileTracker.getFile(path);
|
||||
return FileResultImpl(
|
||||
currentSession, path, file.uri, file.lineInfo, file.isPart);
|
||||
}
|
||||
|
||||
/// Return a [Future] that completes with the list of added files that
|
||||
/// define a class member with the given [name].
|
||||
Future<List<String>> getFilesDefiningClassMemberName(String name) {
|
||||
|
@ -679,7 +666,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
/// Return the [FileResult] for the Dart file with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
@Deprecated('Use getFile() instead')
|
||||
SomeFileResult getFileSync(String path) {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
|
@ -695,7 +681,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
/// Return the [FileResult] for the Dart file with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
@Deprecated('Use getFile() instead')
|
||||
@Deprecated('Use getFileSync() instead')
|
||||
SomeFileResult getFileSync2(String path) {
|
||||
return getFileSync(path);
|
||||
}
|
||||
|
@ -784,7 +770,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
/// Return a [ParsedLibraryResult] for the library with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
@Deprecated('Use getParsedLibrary2() instead')
|
||||
SomeParsedLibraryResult getParsedLibrary(String path) {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
|
@ -813,39 +798,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
return ParsedLibraryResultImpl(currentSession, units);
|
||||
}
|
||||
|
||||
/// Return a [ParsedLibraryResult] for the library with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
Future<SomeParsedLibraryResult> getParsedLibrary2(String path) async {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
}
|
||||
|
||||
if (!_fsState.hasUri(path)) {
|
||||
return NotPathOfUriResult();
|
||||
}
|
||||
|
||||
FileState file = _fsState.getFileForPath(path);
|
||||
|
||||
if (file.isPart) {
|
||||
return NotLibraryButPartResult();
|
||||
}
|
||||
|
||||
var units = <ParsedUnitResult>[];
|
||||
for (var unitFile in file.libraryFiles) {
|
||||
var unitPath = unitFile.path;
|
||||
var unitResult = await parseFile(unitPath);
|
||||
if (unitResult is! ParsedUnitResult) {
|
||||
return UnspecifiedInvalidResult();
|
||||
}
|
||||
units.add(unitResult);
|
||||
}
|
||||
|
||||
return ParsedLibraryResultImpl(currentSession, units);
|
||||
}
|
||||
|
||||
/// Return a [ParsedLibraryResult] for the library with the given [uri].
|
||||
@Deprecated('Use getParsedLibraryByUri2() instead')
|
||||
SomeParsedLibraryResult getParsedLibraryByUri(Uri uri) {
|
||||
var fileOr = _fsState.getFileForUri(uri);
|
||||
return fileOr.map(
|
||||
|
@ -864,25 +817,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
);
|
||||
}
|
||||
|
||||
/// Return a [ParsedLibraryResult] for the library with the given [uri].
|
||||
Future<SomeParsedLibraryResult> getParsedLibraryByUri2(Uri uri) async {
|
||||
var fileOr = _fsState.getFileForUri(uri);
|
||||
return fileOr.map(
|
||||
(file) {
|
||||
if (file == null) {
|
||||
return CannotResolveUriResult();
|
||||
}
|
||||
if (file.isPart) {
|
||||
return NotLibraryButPartResult();
|
||||
}
|
||||
return getParsedLibrary2(file.path);
|
||||
},
|
||||
(externalLibrary) {
|
||||
return UriOfExternalLibraryResult();
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
/// Return a [Future] that completes with a [ResolvedLibraryResult] for the
|
||||
/// Dart library file with the given [path]. If the file cannot be analyzed,
|
||||
/// the [Future] completes with an [InvalidResult].
|
||||
|
@ -1071,27 +1005,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
);
|
||||
}
|
||||
|
||||
/// Return a [ParsedUnitResult] for the file with the given [path].
|
||||
///
|
||||
/// The [path] must be absolute and normalized.
|
||||
///
|
||||
/// The [path] can be any file - explicitly or implicitly analyzed, or neither.
|
||||
///
|
||||
/// The parsing is performed in the method itself, and the result is not
|
||||
/// produced through the [results] stream (just because it is not a fully
|
||||
/// resolved unit).
|
||||
Future<SomeParsedUnitResult> parseFile(String path) async {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
}
|
||||
|
||||
FileState file = _fileTracker.getFile(path);
|
||||
RecordingErrorListener listener = RecordingErrorListener();
|
||||
CompilationUnit unit = file.parse(listener);
|
||||
return ParsedUnitResultImpl(currentSession, file.path, file.uri,
|
||||
file.content, file.lineInfo, file.isPart, unit, listener.errors);
|
||||
}
|
||||
|
||||
/// Return a [Future] that completes with a [ParsedUnitResult] for the file
|
||||
/// with the given [path].
|
||||
///
|
||||
|
@ -1102,7 +1015,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
/// The parsing is performed in the method itself, and the result is not
|
||||
/// produced through the [results] stream (just because it is not a fully
|
||||
/// resolved unit).
|
||||
@Deprecated('Use parseFile() instead')
|
||||
@Deprecated('Use parseFileSync() instead')
|
||||
Future<SomeParsedUnitResult> parseFile2(String path) async {
|
||||
return parseFileSync2(path);
|
||||
}
|
||||
|
@ -1116,7 +1029,6 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
/// The parsing is performed in the method itself, and the result is not
|
||||
/// produced through the [results] stream (just because it is not a fully
|
||||
/// resolved unit).
|
||||
@Deprecated('Use parseFile() instead')
|
||||
SomeParsedUnitResult parseFileSync(String path) {
|
||||
if (!_isAbsolutePath(path)) {
|
||||
return InvalidPathResult();
|
||||
|
|
|
@ -62,7 +62,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Deprecated('Use getFile2() instead')
|
||||
@override
|
||||
SomeFileResult getFile(String path) {
|
||||
_checkConsistency();
|
||||
|
@ -71,14 +70,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeFileResult> getFile2(String path) async {
|
||||
_checkConsistency();
|
||||
var result = await _driver.getFile(path);
|
||||
_checkConsistency();
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeLibraryElementResult> getLibraryByUri(String uri) async {
|
||||
_checkConsistency();
|
||||
|
@ -87,7 +78,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@Deprecated('Use getParsedLibrary2() instead')
|
||||
@override
|
||||
SomeParsedLibraryResult getParsedLibrary(String path) {
|
||||
_checkConsistency();
|
||||
|
@ -96,15 +86,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeParsedLibraryResult> getParsedLibrary2(String path) async {
|
||||
_checkConsistency();
|
||||
var result = await _driver.getParsedLibrary2(path);
|
||||
_checkConsistency();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated('Use getParsedLibraryByElement2() instead')
|
||||
@override
|
||||
SomeParsedLibraryResult getParsedLibraryByElement(LibraryElement element) {
|
||||
_checkConsistency();
|
||||
|
@ -118,22 +99,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeParsedLibraryResult> getParsedLibraryByElement2(
|
||||
LibraryElement element,
|
||||
) async {
|
||||
_checkConsistency();
|
||||
|
||||
if (element.session != this) {
|
||||
return NotElementOfThisSessionResult();
|
||||
}
|
||||
|
||||
var result = await _driver.getParsedLibraryByUri2(element.source.uri);
|
||||
_checkConsistency();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Deprecated('Use getParsedUnit2() instead')
|
||||
@override
|
||||
SomeParsedUnitResult getParsedUnit(String path) {
|
||||
_checkConsistency();
|
||||
|
@ -142,14 +107,6 @@ class AnalysisSessionImpl implements AnalysisSession {
|
|||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeParsedUnitResult> getParsedUnit2(String path) async {
|
||||
_checkConsistency();
|
||||
var result = await _driver.parseFile(path);
|
||||
_checkConsistency();
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<SomeResolvedLibraryResult> getResolvedLibrary(String path) async {
|
||||
_checkConsistency();
|
||||
|
|
|
@ -28,9 +28,9 @@ import 'a.dart';
|
|||
|
||||
// Ask for files, so that they are known.
|
||||
var analysisSession = analysisContext.currentSession;
|
||||
await analysisSession.getFile2(a.path);
|
||||
await analysisSession.getFile2(b.path);
|
||||
await analysisSession.getFile2(c.path);
|
||||
analysisSession.getFile(a.path);
|
||||
analysisSession.getFile(b.path);
|
||||
analysisSession.getFile(c.path);
|
||||
|
||||
analysisContext.changeFile(a.path);
|
||||
|
||||
|
@ -59,10 +59,10 @@ import 'a.dart';
|
|||
|
||||
// Ask for files, so that they are known.
|
||||
var analysisSession = analysisContext.currentSession;
|
||||
await analysisSession.getFile2(a.path);
|
||||
await analysisSession.getFile2(b.path);
|
||||
await analysisSession.getFile2(c.path);
|
||||
await analysisSession.getFile2(d.path);
|
||||
analysisSession.getFile(a.path);
|
||||
analysisSession.getFile(b.path);
|
||||
analysisSession.getFile(c.path);
|
||||
analysisSession.getFile(d.path);
|
||||
|
||||
analysisContext.changeFile(b.path);
|
||||
|
||||
|
|
|
@ -1386,67 +1386,6 @@ bbb() {}
|
|||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getFile_changedFile() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
||||
newFile2(a, '');
|
||||
newFile2(b, r'''
|
||||
import 'a.dart';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
|
||||
// Ensure that [a.dart] library cycle is loaded.
|
||||
// So, `a.dart` is in the library context.
|
||||
await driver.getResultValid(a);
|
||||
|
||||
// Update the file, changing its API signature.
|
||||
// Note that we don't call `changeFile`.
|
||||
newFile2(a, 'class A {}\n');
|
||||
|
||||
// Get the file.
|
||||
// We have not called `changeFile(a)`, so we should not read the file.
|
||||
// Moreover, doing this will create a new library cycle [a.dart].
|
||||
// Library cycles are compared by their identity, so we would try to
|
||||
// reload linked summary for [a.dart], and crash.
|
||||
expect((await driver.getFileValid(a)).lineInfo.lineCount, 1);
|
||||
|
||||
// We have not read `a.dart`, so `A` is still not declared.
|
||||
expect((await driver.getResultValid(b)).errors, isNotEmpty);
|
||||
|
||||
// Notify the driver that the file was changed.
|
||||
driver.changeFile(a);
|
||||
await driver.applyPendingFileChanges();
|
||||
|
||||
// So, `class A {}` is declared now.
|
||||
expect((await driver.getFileValid(a)).lineInfo.lineCount, 2);
|
||||
expect((await driver.getResultValid(b)).errors, isEmpty);
|
||||
}
|
||||
|
||||
test_getFile_library() async {
|
||||
var path = convertPath('/test/lib/a.dart');
|
||||
newFile2(path, '');
|
||||
var file = await driver.getFileValid(path);
|
||||
expect(file.path, path);
|
||||
expect(file.uri.toString(), 'package:test/a.dart');
|
||||
expect(file.isPart, isFalse);
|
||||
}
|
||||
|
||||
test_getFile_notAbsolutePath() async {
|
||||
var result = await driver.getFile('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getFile_part() async {
|
||||
var path = convertPath('/test/lib/a.dart');
|
||||
newFile2(path, 'part of lib;');
|
||||
var file = await driver.getFileValid(path);
|
||||
expect(file.path, path);
|
||||
expect(file.uri.toString(), 'package:test/a.dart');
|
||||
expect(file.isPart, isTrue);
|
||||
}
|
||||
|
||||
test_getFilesDefiningClassMemberName_class() async {
|
||||
var a = convertPath('/test/bin/a.dart');
|
||||
var b = convertPath('/test/bin/b.dart');
|
||||
|
@ -1550,7 +1489,6 @@ void f(A a) {}
|
|||
expect(files, isNot(contains(c)));
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFileSync_changedFile() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
@ -1588,7 +1526,6 @@ void f(A a) {}
|
|||
expect((await driver.getResultValid(b)).errors, isEmpty);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFileSync_library() async {
|
||||
var path = convertPath('/test/lib/a.dart');
|
||||
newFile2(path, '');
|
||||
|
@ -1598,13 +1535,11 @@ void f(A a) {}
|
|||
expect(file.isPart, isFalse);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFileSync_notAbsolutePath() async {
|
||||
var result = driver.getFileSync('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFileSync_part() async {
|
||||
var path = convertPath('/test/lib/a.dart');
|
||||
newFile2(path, 'part of lib;');
|
||||
|
@ -1673,7 +1608,6 @@ class B {}
|
|||
expect(result, isA<CannotResolveUriResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary() async {
|
||||
var content = 'class A {}';
|
||||
addTestFile(content);
|
||||
|
@ -1686,43 +1620,17 @@ class B {}
|
|||
expect(result.units[0].errors, isEmpty);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2() async {
|
||||
var content = 'class A {}';
|
||||
addTestFile(content);
|
||||
var result = await driver.getParsedLibrary2(testFile);
|
||||
result as ParsedLibraryResult;
|
||||
expect(result.units, hasLength(1));
|
||||
expect(result.units[0].path, testFile);
|
||||
expect(result.units[0].content, content);
|
||||
expect(result.units[0].unit, isNotNull);
|
||||
expect(result.units[0].errors, isEmpty);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_invalidPath_notAbsolute() async {
|
||||
var result = await driver.getParsedLibrary2('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_notLibraryButPart() async {
|
||||
addTestFile('part of my;');
|
||||
var result = await driver.getParsedLibrary2(testFile);
|
||||
expect(result, isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_invalidPath_notAbsolute() async {
|
||||
var result = driver.getParsedLibrary('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_notLibraryButPart() async {
|
||||
addTestFile('part of my;');
|
||||
var result = driver.getParsedLibrary(testFile);
|
||||
expect(result, isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibraryByUri() async {
|
||||
var content = 'class A {}';
|
||||
addTestFile(content);
|
||||
|
@ -1736,34 +1644,6 @@ class B {}
|
|||
expect(result.units[0].content, content);
|
||||
}
|
||||
|
||||
test_getParsedLibraryByUri2() async {
|
||||
var content = 'class A {}';
|
||||
addTestFile(content);
|
||||
|
||||
var uri = Uri.parse('package:test/test.dart');
|
||||
var result = await driver.getParsedLibraryByUri2(uri);
|
||||
result as ParsedLibraryResult;
|
||||
expect(result.units, hasLength(1));
|
||||
expect(result.units[0].uri, uri);
|
||||
expect(result.units[0].path, testFile);
|
||||
expect(result.units[0].content, content);
|
||||
}
|
||||
|
||||
test_getParsedLibraryByUri2_notLibrary() async {
|
||||
addTestFile('part of my;');
|
||||
|
||||
var uri = Uri.parse('package:test/test.dart');
|
||||
var result = await driver.getParsedLibraryByUri2(uri);
|
||||
expect(result, isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
test_getParsedLibraryByUri2_unresolvedUri() async {
|
||||
var uri = Uri.parse('package:unknown/a.dart');
|
||||
var result = await driver.getParsedLibraryByUri2(uri);
|
||||
expect(result, isA<CannotResolveUriResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibraryByUri_notLibrary() async {
|
||||
addTestFile('part of my;');
|
||||
|
||||
|
@ -1772,7 +1652,6 @@ class B {}
|
|||
expect(result, isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibraryByUri_unresolvedUri() async {
|
||||
var uri = Uri.parse('package:unknown/a.dart');
|
||||
var result = driver.getParsedLibraryByUri(uri);
|
||||
|
@ -2558,139 +2437,6 @@ import 'b.dart';
|
|||
expect(error.errorCode, CompileTimeErrorCode.MISSING_DART_LIBRARY);
|
||||
}
|
||||
|
||||
test_parseFile_changedFile() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
||||
newFile2(a, '');
|
||||
newFile2(b, r'''
|
||||
import 'a.dart';
|
||||
|
||||
void f(A a) {}
|
||||
''');
|
||||
|
||||
// Ensure that [a.dart] library cycle is loaded.
|
||||
// So, `a.dart` is in the library context.
|
||||
await driver.getResultValid(a);
|
||||
|
||||
// Update the file, changing its API signature.
|
||||
// Note that we don't call `changeFile`.
|
||||
newFile2(a, 'class A {}');
|
||||
|
||||
// Parse the file.
|
||||
// We have not called `changeFile(a)`, so we should not read the file.
|
||||
// Moreover, doing this will create a new library cycle [a.dart].
|
||||
// Library cycles are compared by their identity, so we would try to
|
||||
// reload linked summary for [a.dart], and crash.
|
||||
{
|
||||
var parseResult = await driver.parseFile(a) as ParsedUnitResult;
|
||||
expect(parseResult.unit.declarations, isEmpty);
|
||||
}
|
||||
|
||||
// We have not read `a.dart`, so `A` is still not declared.
|
||||
{
|
||||
var bResult = await driver.getResultValid(b);
|
||||
expect(bResult.errors, isNotEmpty);
|
||||
}
|
||||
|
||||
// Notify the driver that the file was changed.
|
||||
driver.changeFile(a);
|
||||
await driver.applyPendingFileChanges();
|
||||
|
||||
// So, `class A {}` is declared now.
|
||||
{
|
||||
var parseResult = await driver.parseFile(a) as ParsedUnitResult;
|
||||
expect(parseResult.unit.declarations, hasLength(1));
|
||||
}
|
||||
{
|
||||
var bResult = await driver.getResultValid(b);
|
||||
expect(bResult.errors, isEmpty);
|
||||
}
|
||||
}
|
||||
|
||||
test_parseFile_doesNotReadImportedFiles() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
||||
newFile2(a, '');
|
||||
newFile2(b, r'''
|
||||
import 'a.dart';
|
||||
''');
|
||||
|
||||
expect(driver.fsState.knownFilePaths, isEmpty);
|
||||
|
||||
// Don't read `a.dart` when parse.
|
||||
await driver.parseFile(b);
|
||||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
|
||||
// Still don't read `a.dart` when parse the second time.
|
||||
await driver.parseFile(b);
|
||||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
}
|
||||
|
||||
test_parseFile_doesNotReadPartedFiles() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
||||
newFile2(a, r'''
|
||||
part of my;
|
||||
''');
|
||||
newFile2(b, r'''
|
||||
library my;
|
||||
part 'a.dart';
|
||||
''');
|
||||
|
||||
expect(driver.fsState.knownFilePaths, isEmpty);
|
||||
|
||||
// Don't read `a.dart` when parse.
|
||||
await driver.parseFile(b);
|
||||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
|
||||
// Still don't read `a.dart` when parse the second time.
|
||||
await driver.parseFile(b);
|
||||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
}
|
||||
|
||||
test_parseFile_languageVersion() async {
|
||||
var path = convertPath('/test/lib/test.dart');
|
||||
|
||||
newFile2(path, r'''
|
||||
// @dart = 2.7
|
||||
class A {}
|
||||
''');
|
||||
|
||||
var parseResult = await driver.parseFile(path) as ParsedUnitResult;
|
||||
var languageVersion = parseResult.unit.languageVersionToken!;
|
||||
expect(languageVersion.major, 2);
|
||||
expect(languageVersion.minor, 7);
|
||||
}
|
||||
|
||||
test_parseFile_languageVersion_null() async {
|
||||
var path = convertPath('/test/lib/test.dart');
|
||||
|
||||
newFile2(path, r'''
|
||||
class A {}
|
||||
''');
|
||||
|
||||
var parseResult = await driver.parseFile(path) as ParsedUnitResult;
|
||||
expect(parseResult.unit.languageVersionToken, isNull);
|
||||
}
|
||||
|
||||
test_parseFile_notAbsolutePath() async {
|
||||
var result = await driver.parseFile('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_parseFile_notDart() async {
|
||||
var p = convertPath('/test/bin/a.txt');
|
||||
newFile2(p, 'class A {}');
|
||||
|
||||
var parseResult = await driver.parseFile(p) as ParsedUnitResult;
|
||||
expect(parseResult, isNotNull);
|
||||
expect(driver.knownFiles, contains(p));
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_changedFile() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
@ -2740,7 +2486,6 @@ void f(A a) {}
|
|||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_doesNotReadImportedFiles() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
@ -2761,7 +2506,6 @@ import 'a.dart';
|
|||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_doesNotReadPartedFiles() async {
|
||||
var a = convertPath('/test/lib/a.dart');
|
||||
var b = convertPath('/test/lib/b.dart');
|
||||
|
@ -2785,7 +2529,6 @@ part 'a.dart';
|
|||
expect(driver.fsState.knownFilePaths, unorderedEquals([b]));
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_languageVersion() async {
|
||||
var path = convertPath('/test/lib/test.dart');
|
||||
|
||||
|
@ -2800,7 +2543,6 @@ class A {}
|
|||
expect(languageVersion.minor, 7);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_languageVersion_null() async {
|
||||
var path = convertPath('/test/lib/test.dart');
|
||||
|
||||
|
@ -2812,13 +2554,11 @@ class A {}
|
|||
expect(parseResult.unit.languageVersionToken, isNull);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_notAbsolutePath() async {
|
||||
var result = driver.parseFileSync('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_parseFileSync_notDart() async {
|
||||
var p = convertPath('/test/bin/a.txt');
|
||||
newFile2(p, 'class A {}');
|
||||
|
@ -3717,15 +3457,10 @@ extension on AnalysisDriver {
|
|||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
FileResult getFileSyncValid(String path) {
|
||||
return getFileSync(path) as FileResult;
|
||||
}
|
||||
|
||||
Future<FileResult> getFileValid(String path) async {
|
||||
return await getFile(path) as FileResult;
|
||||
}
|
||||
|
||||
Future<LibraryElementResult> getLibraryByUriValid(String uriStr) async {
|
||||
return await getLibraryByUri(uriStr) as LibraryElementResult;
|
||||
}
|
||||
|
|
|
@ -461,7 +461,7 @@ mixin M on foo^ {}
|
|||
newFile2(testFilePath, 'class A {}');
|
||||
|
||||
// Read the file.
|
||||
await testDriver.getFile(testFilePathPlatform);
|
||||
testDriver.getFileSync(testFilePathPlatform);
|
||||
|
||||
// Should call `changeFile()`, and the driver must re-read the file.
|
||||
var result = await _resolveTestCode(r'''
|
||||
|
|
|
@ -439,7 +439,7 @@ class GetElementDeclarationParsedTest extends PubPackageResolutionTest
|
|||
|
||||
Future<ParsedLibraryResult> _getParsedLibrary(String path) async {
|
||||
var session = contextFor(path).currentSession;
|
||||
return await session.getParsedLibrary2(path) as ParsedLibraryResult;
|
||||
return session.getParsedLibrary(path) as ParsedLibraryResult;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -44,17 +44,6 @@ class AnalysisSessionImpl_BazelWorkspaceTest
|
|||
expect(result.uri.toString(), 'package:dart.my/a.dart');
|
||||
}
|
||||
|
||||
void test_getParsedLibrary2_notFileOfUri() async {
|
||||
var relPath = 'dart/my/lib/a.dart';
|
||||
newFile2('$workspaceRootPath/bazel-bin/$relPath', '');
|
||||
|
||||
var path = convertPath('$workspaceRootPath/$relPath');
|
||||
var session = contextFor(path).currentSession;
|
||||
var result = await session.getParsedLibrary2(path);
|
||||
expect(result, isA<NotPathOfUriResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
void test_getParsedLibrary_notFileOfUri() async {
|
||||
var relPath = 'dart/my/lib/a.dart';
|
||||
newFile2('$workspaceRootPath/bazel-bin/$relPath', '');
|
||||
|
@ -161,43 +150,6 @@ class AnalysisSessionImplTest extends PubPackageResolutionTest {
|
|||
expect(errorsResult, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getFile2_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
driverFor(test.path).changeFile(test.path);
|
||||
expect(
|
||||
() async => session.getFile2(test.path),
|
||||
throwsA(isA<InconsistentAnalysisException>()),
|
||||
);
|
||||
}
|
||||
|
||||
test_getFile2_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var errorsResult = await session.getFile2('not_absolute.dart');
|
||||
expect(errorsResult, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getFile2_library() async {
|
||||
var a = newFile2('$testPackageLibPath/a.dart', '');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var file = await session.getFile2Valid(a.path);
|
||||
expect(file.path, a.path);
|
||||
expect(file.uri.toString(), 'package:test/a.dart');
|
||||
expect(file.isPart, isFalse);
|
||||
}
|
||||
|
||||
test_getFile2_part() async {
|
||||
var a = newFile2('$testPackageLibPath/a.dart', 'part of lib;');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var file = await session.getFile2Valid(a.path);
|
||||
expect(file.path, a.path);
|
||||
expect(file.uri.toString(), 'package:test/a.dart');
|
||||
expect(file.isPart, isTrue);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFile_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
|
@ -208,14 +160,12 @@ class AnalysisSessionImplTest extends PubPackageResolutionTest {
|
|||
);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFile_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var errorsResult = session.getFile('not_absolute.dart');
|
||||
expect(errorsResult, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFile_library() async {
|
||||
var a = newFile2('$testPackageLibPath/a.dart', '');
|
||||
|
||||
|
@ -226,7 +176,6 @@ class AnalysisSessionImplTest extends PubPackageResolutionTest {
|
|||
expect(file.isPart, isFalse);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getFile_part() async {
|
||||
var a = newFile2('$testPackageLibPath/a.dart', 'part of lib;');
|
||||
|
||||
|
@ -267,7 +216,6 @@ class B {}
|
|||
expect(result, isA<CannotResolveUriResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary() async {
|
||||
var test = newFile2('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
|
@ -288,189 +236,6 @@ class B {}
|
|||
}
|
||||
}
|
||||
|
||||
test_getParsedLibrary2() async {
|
||||
var test = newFile2('$testPackageLibPath/a.dart', r'''
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(test.path);
|
||||
expect(parsedLibrary.session, session);
|
||||
|
||||
expect(parsedLibrary.units, hasLength(1));
|
||||
{
|
||||
var parsedUnit = parsedLibrary.units[0];
|
||||
expect(parsedUnit.session, session);
|
||||
expect(parsedUnit.path, test.path);
|
||||
expect(parsedUnit.uri, Uri.parse('package:test/a.dart'));
|
||||
expect(parsedUnit.unit.declarations, hasLength(2));
|
||||
}
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_getElementDeclaration_class() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var libraryResult = await session.getLibraryByUriValid(
|
||||
'package:test/test.dart',
|
||||
);
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(test.path);
|
||||
|
||||
var element = libraryResult.element.getType('A')!;
|
||||
var declaration = parsedLibrary.getElementDeclaration(element)!;
|
||||
var node = declaration.node as ClassDeclaration;
|
||||
expect(node.name.name, 'A');
|
||||
expect(node.offset, 0);
|
||||
expect(node.length, 10);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_getElementDeclaration_notThisLibrary() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var resolvedUnit =
|
||||
await session.getResolvedUnit(test.path) as ResolvedUnitResult;
|
||||
var typeProvider = resolvedUnit.typeProvider;
|
||||
var intClass = typeProvider.intType.element;
|
||||
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(test.path);
|
||||
|
||||
expect(() {
|
||||
parsedLibrary.getElementDeclaration(intClass);
|
||||
}, throwsArgumentError);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_getElementDeclaration_synthetic() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
int foo = 0;
|
||||
''');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(test.path);
|
||||
|
||||
var unitResult = await session.getUnitElementValid(test.path);
|
||||
var fooElement = unitResult.element.topLevelVariables[0];
|
||||
expect(fooElement.name, 'foo');
|
||||
|
||||
// We can get the variable element declaration.
|
||||
var fooDeclaration = parsedLibrary.getElementDeclaration(fooElement)!;
|
||||
var fooNode = fooDeclaration.node as VariableDeclaration;
|
||||
expect(fooNode.name.name, 'foo');
|
||||
expect(fooNode.offset, 4);
|
||||
expect(fooNode.length, 7);
|
||||
expect(fooNode.name.staticElement, isNull);
|
||||
|
||||
// Synthetic elements don't have nodes.
|
||||
expect(parsedLibrary.getElementDeclaration(fooElement.getter!), isNull);
|
||||
expect(parsedLibrary.getElementDeclaration(fooElement.setter!), isNull);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
driverFor(test.path).changeFile(test.path);
|
||||
expect(
|
||||
() => session.getParsedLibrary2(test.path),
|
||||
throwsA(isA<InconsistentAnalysisException>()),
|
||||
);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_invalidPartUri() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
part 'a.dart';
|
||||
part ':[invalid uri].dart';
|
||||
part 'c.dart';
|
||||
''');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(test.path);
|
||||
|
||||
expect(parsedLibrary.units, hasLength(3));
|
||||
expect(
|
||||
parsedLibrary.units[0].path,
|
||||
convertPath('/home/test/lib/test.dart'),
|
||||
);
|
||||
expect(
|
||||
parsedLibrary.units[1].path,
|
||||
convertPath('/home/test/lib/a.dart'),
|
||||
);
|
||||
expect(
|
||||
parsedLibrary.units[2].path,
|
||||
convertPath('/home/test/lib/c.dart'),
|
||||
);
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var result = await session.getParsedLibrary2('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_notLibrary() async {
|
||||
var test = newFile2(testFilePath, 'part of "a.dart";');
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var result = await session.getParsedLibrary2(test.path);
|
||||
expect(result, isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
test_getParsedLibrary2_parts() async {
|
||||
var aContent = r'''
|
||||
part 'b.dart';
|
||||
part 'c.dart';
|
||||
|
||||
class A {}
|
||||
''';
|
||||
|
||||
var bContent = r'''
|
||||
part of 'a.dart';
|
||||
|
||||
class B1 {}
|
||||
class B2 {}
|
||||
''';
|
||||
|
||||
var cContent = r'''
|
||||
part of 'a.dart';
|
||||
|
||||
class C1 {}
|
||||
class C2 {}
|
||||
class C3 {}
|
||||
''';
|
||||
|
||||
var a = newFile2('$testPackageLibPath/a.dart', aContent);
|
||||
var b = newFile2('$testPackageLibPath/b.dart', bContent);
|
||||
var c = newFile2('$testPackageLibPath/c.dart', cContent);
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var parsedLibrary = await session.getParsedLibrary2Valid(a.path);
|
||||
expect(parsedLibrary.units, hasLength(3));
|
||||
|
||||
{
|
||||
var aUnit = parsedLibrary.units[0];
|
||||
expect(aUnit.path, a.path);
|
||||
expect(aUnit.uri, Uri.parse('package:test/a.dart'));
|
||||
expect(aUnit.unit.declarations, hasLength(1));
|
||||
}
|
||||
|
||||
{
|
||||
var bUnit = parsedLibrary.units[1];
|
||||
expect(bUnit.path, b.path);
|
||||
expect(bUnit.uri, Uri.parse('package:test/b.dart'));
|
||||
expect(bUnit.unit.declarations, hasLength(2));
|
||||
}
|
||||
|
||||
{
|
||||
var cUnit = parsedLibrary.units[2];
|
||||
expect(cUnit.path, c.path);
|
||||
expect(cUnit.uri, Uri.parse('package:test/c.dart'));
|
||||
expect(cUnit.unit.declarations, hasLength(3));
|
||||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_getElementDeclaration_class() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
class A {}
|
||||
|
@ -491,7 +256,6 @@ class B {}
|
|||
expect(node.length, 10);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_getElementDeclaration_notThisLibrary() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
|
||||
|
@ -508,7 +272,6 @@ class B {}
|
|||
}, throwsArgumentError);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_getElementDeclaration_synthetic() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
int foo = 0;
|
||||
|
@ -534,7 +297,6 @@ int foo = 0;
|
|||
expect(parsedLibrary.getElementDeclaration(fooElement.setter!), isNull);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
|
@ -545,7 +307,6 @@ int foo = 0;
|
|||
);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_invalidPartUri() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
part 'a.dart';
|
||||
|
@ -571,21 +332,18 @@ part 'c.dart';
|
|||
);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var result = session.getParsedLibrary('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_notLibrary() async {
|
||||
var test = newFile2(testFilePath, 'part of "a.dart";');
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
expect(session.getParsedLibrary(test.path), isA<NotLibraryButPartResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibrary_parts() async {
|
||||
var aContent = r'''
|
||||
part 'b.dart';
|
||||
|
@ -639,7 +397,6 @@ class C3 {}
|
|||
}
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibraryByElement() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
|
||||
|
@ -661,43 +418,6 @@ class C3 {}
|
|||
}
|
||||
}
|
||||
|
||||
test_getParsedLibraryByElement2() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var libraryResult = await session.getLibraryByUriValid(
|
||||
'package:test/test.dart',
|
||||
);
|
||||
var element = libraryResult.element;
|
||||
|
||||
var parsedLibrary = await session.getParsedLibraryByElement2Valid(element);
|
||||
expect(parsedLibrary.session, session);
|
||||
expect(parsedLibrary.units, hasLength(1));
|
||||
|
||||
{
|
||||
var unit = parsedLibrary.units[0];
|
||||
expect(unit.path, test.path);
|
||||
expect(unit.uri, Uri.parse('package:test/test.dart'));
|
||||
expect(unit.unit, isNotNull);
|
||||
}
|
||||
}
|
||||
|
||||
test_getParsedLibraryByElement2_differentSession() async {
|
||||
newFile2(testFilePath, '');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var libraryResult = await session.getLibraryByUriValid(
|
||||
'package:test/test.dart',
|
||||
);
|
||||
var element = libraryResult.element;
|
||||
|
||||
var aaaSession = contextFor('$workspaceRootPath/aaa').currentSession;
|
||||
|
||||
var result = await aaaSession.getParsedLibraryByElement2(element);
|
||||
expect(result, isA<NotElementOfThisSessionResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedLibraryByElement_differentSession() async {
|
||||
newFile2(testFilePath, '');
|
||||
|
||||
|
@ -713,7 +433,6 @@ class C3 {}
|
|||
expect(result, isA<NotElementOfThisSessionResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedUnit() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
class A {}
|
||||
|
@ -728,37 +447,6 @@ class B {}
|
|||
expect(unitResult.unit.declarations, hasLength(2));
|
||||
}
|
||||
|
||||
test_getParsedUnit2() async {
|
||||
var test = newFile2(testFilePath, r'''
|
||||
class A {}
|
||||
class B {}
|
||||
''');
|
||||
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var unitResult = await session.getParsedUnit2Valid(test.path);
|
||||
expect(unitResult.session, session);
|
||||
expect(unitResult.path, test.path);
|
||||
expect(unitResult.uri, Uri.parse('package:test/test.dart'));
|
||||
expect(unitResult.unit.declarations, hasLength(2));
|
||||
}
|
||||
|
||||
test_getParsedUnit2_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
driverFor(test.path).changeFile(test.path);
|
||||
expect(
|
||||
() => session.getParsedUnit2(test.path),
|
||||
throwsA(isA<InconsistentAnalysisException>()),
|
||||
);
|
||||
}
|
||||
|
||||
test_getParsedUnit2_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var result = await session.getParsedUnit2('not_absolute.dart');
|
||||
expect(result, isA<InvalidPathResult>());
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedUnit_inconsistent() async {
|
||||
var test = newFile2(testFilePath, '');
|
||||
var session = contextFor(test.path).currentSession;
|
||||
|
@ -769,7 +457,6 @@ class B {}
|
|||
);
|
||||
}
|
||||
|
||||
@deprecated
|
||||
test_getParsedUnit_invalidPath_notAbsolute() async {
|
||||
var session = contextFor(testFilePath).currentSession;
|
||||
var result = session.getParsedUnit('not_absolute.dart');
|
||||
|
@ -1018,11 +705,6 @@ extension on AnalysisSession {
|
|||
return await getErrors(path) as ErrorsResult;
|
||||
}
|
||||
|
||||
Future<FileResult> getFile2Valid(String path) async {
|
||||
return await getFile2(path) as FileResult;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
FileResult getFileValid(String path) {
|
||||
return getFile(path) as FileResult;
|
||||
}
|
||||
|
@ -1031,31 +713,14 @@ extension on AnalysisSession {
|
|||
return await getLibraryByUri(path) as LibraryElementResult;
|
||||
}
|
||||
|
||||
Future<ParsedLibraryResult> getParsedLibrary2Valid(String path) async {
|
||||
return await getParsedLibrary2(path) as ParsedLibraryResult;
|
||||
}
|
||||
|
||||
Future<ParsedLibraryResult> getParsedLibraryByElement2Valid(
|
||||
LibraryElement element,
|
||||
) async {
|
||||
return await getParsedLibraryByElement2(element) as ParsedLibraryResult;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
ParsedLibraryResult getParsedLibraryByElementValid(LibraryElement element) {
|
||||
return getParsedLibraryByElement(element) as ParsedLibraryResult;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
ParsedLibraryResult getParsedLibraryValid(String path) {
|
||||
return getParsedLibrary(path) as ParsedLibraryResult;
|
||||
}
|
||||
|
||||
Future<ParsedUnitResult> getParsedUnit2Valid(String path) async {
|
||||
return await getParsedUnit2(path) as ParsedUnitResult;
|
||||
}
|
||||
|
||||
@deprecated
|
||||
ParsedUnitResult getParsedUnitValid(String path) {
|
||||
return getParsedUnit(path) as ParsedUnitResult;
|
||||
}
|
||||
|
|
|
@ -3491,9 +3491,9 @@ class C {}
|
|||
newFile2(a, 'class A {}');
|
||||
newFile2(b, 'class B {}');
|
||||
newFile2(c, 'class C {}');
|
||||
await testAnalysisContext.currentSession.getFile2(a);
|
||||
await testAnalysisContext.currentSession.getFile2(b);
|
||||
await testAnalysisContext.currentSession.getFile2(c);
|
||||
testAnalysisContext.currentSession.getFile(a);
|
||||
testAnalysisContext.currentSession.getFile(b);
|
||||
testAnalysisContext.currentSession.getFile(c);
|
||||
|
||||
var context = tracker.addContext(testAnalysisContext);
|
||||
await _doAllTrackerWork();
|
||||
|
|
|
@ -311,7 +311,7 @@ class HumanErrorFormatter extends ErrorFormatter {
|
|||
// TODO(scheglov) We should add `LineInfo` to `DiagnosticMessage`.
|
||||
var session = result.session.analysisContext;
|
||||
if (session is DriverBasedAnalysisContext) {
|
||||
var fileResult = await session.driver.getFile(message.filePath);
|
||||
var fileResult = session.driver.getFileSync(message.filePath);
|
||||
if (fileResult is FileResult) {
|
||||
var lineInfo = fileResult.lineInfo;
|
||||
var location = lineInfo.getLocation(message.offset);
|
||||
|
|
|
@ -103,7 +103,7 @@ class VerifyTests {
|
|||
if (isOkForTestAllToBeMissing(directory)) {
|
||||
fail('Found "test_all.dart" in $relativePath but did not expect one');
|
||||
}
|
||||
var result = await session.getParsedUnit2(testAllFile.path);
|
||||
var result = session.getParsedUnit(testAllFile.path);
|
||||
if (result is! ParsedUnitResult) {
|
||||
fail('Could not parse ${testAllFile.path}');
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import 'package:analyzer/dart/analysis/results.dart';
|
|||
import 'package:analyzer/dart/ast/ast.dart';
|
||||
import 'package:test_runner/src/path.dart';
|
||||
|
||||
Future<void> main(List<String> arguments) async {
|
||||
void main(List<String> arguments) {
|
||||
_initAnalysisContext();
|
||||
|
||||
var suites = Directory('tests').listSync();
|
||||
|
@ -26,14 +26,14 @@ Future<void> main(List<String> arguments) async {
|
|||
for (var entry in suites) {
|
||||
// Skip the co19 tests since they don't use '_test.dart'.
|
||||
if (entry is Directory && !entry.path.contains('co19')) {
|
||||
await _checkTestDirectory(entry);
|
||||
_checkTestDirectory(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AnalysisContext _analysisContext;
|
||||
|
||||
Future<void> _checkTestDirectory(Directory directory) async {
|
||||
void _checkTestDirectory(Directory directory) {
|
||||
print('-- ${directory.path} --');
|
||||
var paths = directory
|
||||
.listSync(recursive: true)
|
||||
|
@ -46,7 +46,7 @@ Future<void> _checkTestDirectory(Directory directory) async {
|
|||
print('Finding referenced files...');
|
||||
var importedPaths = <String>{};
|
||||
for (var path in paths) {
|
||||
await _parseReferences(importedPaths, path);
|
||||
_parseReferences(importedPaths, path);
|
||||
}
|
||||
|
||||
// Find the ".dart" files that don't end in "_test.dart" but also aren't used
|
||||
|
@ -71,11 +71,10 @@ void _initAnalysisContext() {
|
|||
_analysisContext = ContextBuilder().createContext(contextRoot: roots[0]);
|
||||
}
|
||||
|
||||
Future<void> _parseReferences(
|
||||
Set<String> importedPaths, String filePath) async {
|
||||
void _parseReferences(Set<String> importedPaths, String filePath) {
|
||||
var absolute = Path(filePath).absolute.toNativePath();
|
||||
var analysisSession = _analysisContext.currentSession;
|
||||
var parseResult = await analysisSession.getParsedUnit2(absolute);
|
||||
var parseResult = analysisSession.getParsedUnit(absolute);
|
||||
var unit = (parseResult as ParsedUnitResult).unit;
|
||||
|
||||
void add(String importPath) {
|
||||
|
|
Loading…
Reference in a new issue