Make AnalysisResult.path non-nullable, more non-nullable for ParsedLibraryResult and ResolvedLibraryResult.
Change-Id: Iab3a8c6c81ace30049a93d0a453e2473634ba07a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195058
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/lib/src/analysis_server_abstract.dart b/pkg/analysis_server/lib/src/analysis_server_abstract.dart
index 3288d8b..40fcb0f 100644
--- a/pkg/analysis_server/lib/src/analysis_server_abstract.dart
+++ b/pkg/analysis_server/lib/src/analysis_server_abstract.dart
@@ -362,6 +362,7 @@
return driver
.getResult(path, sendCachedToStream: sendCachedToStream)
+ .then((value) => value.state == ResultState.VALID ? value : null)
.catchError((e, st) {
instrumentationService.logException(e, st);
return null;
diff --git a/pkg/analysis_server/lib/src/computer/computer_outline.dart b/pkg/analysis_server/lib/src/computer/computer_outline.dart
index fedd848..deca868 100644
--- a/pkg/analysis_server/lib/src/computer/computer_outline.dart
+++ b/pkg/analysis_server/lib/src/computer/computer_outline.dart
@@ -87,9 +87,6 @@
Location _getLocationOffsetLength(int offset, int length) {
var path = resolvedUnit.path;
- if (path == null) {
- throw StateError('DartUnitOutlineComputer called with invalid result');
- }
var startLocation = resolvedUnit.lineInfo.getLocation(offset);
var startLine = startLocation.lineNumber;
var startColumn = startLocation.columnNumber;
diff --git a/pkg/analysis_server/lib/src/computer/import_elements_computer.dart b/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
index 3a2ec51..8ad83ca 100644
--- a/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
+++ b/pkg/analysis_server/lib/src/computer/import_elements_computer.dart
@@ -33,7 +33,7 @@
List<ImportedElements> importedElementsList) async {
var unit = libraryResult.unit;
var path = libraryResult.path;
- if (unit == null || path == null) {
+ if (unit == null) {
// We should never reach this point because the libraryResult should be
// valid.
return SourceChange('');
diff --git a/pkg/analysis_server/lib/src/domain_analysis.dart b/pkg/analysis_server/lib/src/domain_analysis.dart
index 0cec373..c557341 100644
--- a/pkg/analysis_server/lib/src/domain_analysis.dart
+++ b/pkg/analysis_server/lib/src/domain_analysis.dart
@@ -61,7 +61,7 @@
// Prepare the resolved units.
var result = await server.getResolvedUnit(file);
- if (result.state != ResultState.VALID) {
+ if (result == null) {
server.sendResponse(Response.fileNotAnalyzed(request, file));
return;
}
diff --git a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
index 7c029d8..ee2cb5c 100644
--- a/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
+++ b/pkg/analysis_server/lib/src/domains/completion/available_suggestions.dart
@@ -24,7 +24,7 @@
var context = tracker.getContext(analysisContext);
if (context == null) return;
- var librariesObject = context.getLibraries(resolvedUnit.path!);
+ var librariesObject = context.getLibraries(resolvedUnit.path);
var importedUriSet = resolvedUnit.libraryElement.importedLibraries
.map((importedLibrary) => importedLibrary.source.uri)
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
index 7c20027..87310e8 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/completion_manager.dart
@@ -96,7 +96,7 @@
}) async {
request.checkAborted();
var pathContext = request.resourceProvider.pathContext;
- if (!file_paths.isDart(pathContext, request.result.path!)) {
+ if (!file_paths.isDart(pathContext, request.result.path)) {
return const <CompletionSuggestion>[];
}
diff --git a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
index d2ce0e3..9c530a8 100644
--- a/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
+++ b/pkg/analysis_server/lib/src/services/completion/dart/suggestion_builder.dart
@@ -700,7 +700,7 @@
ExecutableElement element, bool invokeSuper) async {
var displayTextBuffer = StringBuffer();
var builder = ChangeBuilder(session: request.result.session);
- await builder.addDartFileEdit(request.result.path!, (builder) {
+ await builder.addDartFileEdit(request.result.path, (builder) {
builder.addReplacement(range.node(targetId), (builder) {
builder.writeOverride(
element,
diff --git a/pkg/analysis_server/lib/src/services/completion/postfix/postfix_completion.dart b/pkg/analysis_server/lib/src/services/completion/postfix/postfix_completion.dart
index 8aa88e2..988a42d 100644
--- a/pkg/analysis_server/lib/src/services/completion/postfix/postfix_completion.dart
+++ b/pkg/analysis_server/lib/src/services/completion/postfix/postfix_completion.dart
@@ -264,7 +264,7 @@
String get eol => utils.endOfLine;
- String get file => completionContext.resolveResult.path!;
+ String get file => completionContext.resolveResult.path;
String get key => completionContext.key;
diff --git a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
index 9bd0039..e71629b 100644
--- a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
+++ b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart
@@ -120,7 +120,7 @@
String get eol => utils.endOfLine;
- String get file => statementContext.resolveResult.path!;
+ String get file => statementContext.resolveResult.path;
LineInfo get lineInfo => statementContext.resolveResult.lineInfo;
diff --git a/pkg/analysis_server/lib/src/services/correction/base_processor.dart b/pkg/analysis_server/lib/src/services/correction/base_processor.dart
index 543d8c9..fb8a04f 100644
--- a/pkg/analysis_server/lib/src/services/correction/base_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/base_processor.dart
@@ -33,7 +33,7 @@
this.selectionLength = 0,
required this.resolvedResult,
required this.workspace,
- }) : file = resolvedResult.path!,
+ }) : file = resolvedResult.path,
session = resolvedResult.session,
sessionHelper = AnalysisSessionHelper(resolvedResult.session),
typeProvider = resolvedResult.typeProvider,
diff --git a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
index 65467c5..50132d8 100644
--- a/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
+++ b/pkg/analysis_server/lib/src/services/correction/bulk_fix_processor.dart
@@ -281,7 +281,7 @@
/// library associated with the analysis [result].
Future<void> _fixErrorsInLibrary(ResolvedLibraryResult result) async {
var analysisOptions = result.session.analysisContext.analysisOptions;
- for (var unitResult in result.units!) {
+ for (var unitResult in result.units) {
var overrideSet = _readOverrideSet(unitResult);
for (var error in unitResult.errors) {
var processor = ErrorProcessor.getProcessor(analysisOptions, error);
@@ -348,7 +348,7 @@
await compute(producer);
var newHash = computeChangeHash();
if (newHash != oldHash) {
- changeMap.add(result.path!, code);
+ changeMap.add(result.path, code);
}
}
@@ -398,7 +398,7 @@
if (useConfigFiles) {
var provider = result.session.resourceProvider;
var context = provider.pathContext;
- var dartFileName = result.path!;
+ var dartFileName = result.path;
var configFileName = '${context.withoutExtension(dartFileName)}.config';
var configFile = provider.getFile(configFileName);
try {
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart b/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart
index a39cc31..7241c32 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/abstract_producer.dart
@@ -248,7 +248,7 @@
this.overrideSet,
this.selectionOffset = -1,
this.selectionLength = 0,
- }) : file = resolvedResult.path!,
+ }) : file = resolvedResult.path,
session = resolvedResult.session,
sessionHelper = AnalysisSessionHelper(resolvedResult.session),
typeProvider = resolvedResult.typeProvider,
diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_part_of_to_uri.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_part_of_to_uri.dart
index 0f22239..c841c0f 100644
--- a/pkg/analysis_server/lib/src/services/correction/dart/convert_part_of_to_uri.dart
+++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_part_of_to_uri.dart
@@ -27,7 +27,7 @@
}
var libraryPath = resolvedResult.libraryElement.source.fullName;
- var partPath = resolvedResult.path!;
+ var partPath = resolvedResult.path;
var relativePath = relative(libraryPath, from: dirname(partPath));
var uri = Uri.file(relativePath).toString();
var replacementRange = range.node(libraryName);
diff --git a/pkg/analysis_server/lib/src/services/flutter/property.dart b/pkg/analysis_server/lib/src/services/flutter/property.dart
index 11af175..0d4f3e3 100644
--- a/pkg/analysis_server/lib/src/services/flutter/property.dart
+++ b/pkg/analysis_server/lib/src/services/flutter/property.dart
@@ -118,7 +118,7 @@
);
}
- await builder.addDartFileEdit(resolvedUnit.path!, (builder) {
+ await builder.addDartFileEdit(resolvedUnit.path, (builder) {
_changeCode(builder, (builder) {
var expression = value.expression;
if (expression != null) {
@@ -155,7 +155,7 @@
}
var beginOffset = argumentExpression.offset;
- await builder.addDartFileEdit(resolvedUnit.path!, (builder) {
+ await builder.addDartFileEdit(resolvedUnit.path, (builder) {
builder.addDeletion(
SourceRange(beginOffset, endOffset - beginOffset),
);
@@ -559,7 +559,7 @@
var builder = ChangeBuilder(session: property.resolvedUnit.session);
- await builder.addDartFileEdit(property.resolvedUnit.path!, (builder) {
+ await builder.addDartFileEdit(property.resolvedUnit.path, (builder) {
property._changeCode(builder, (builder) {
if (leftCode == rightCode && topCode == bottomCode) {
builder.writeReference(classEdgeInsets);
diff --git a/pkg/analysis_server/test/edit/organize_directives_test.dart b/pkg/analysis_server/test/edit/organize_directives_test.dart
index e81ca0e..822589b 100644
--- a/pkg/analysis_server/test/edit/organize_directives_test.dart
+++ b/pkg/analysis_server/test/edit/organize_directives_test.dart
@@ -30,7 +30,6 @@
handler = EditDomainHandler(server);
}
- @failingTest
Future test_BAD_doesNotExist() async {
// The analysis driver fails to return an error
var request =
diff --git a/pkg/analysis_server/test/protocol_server_test.dart b/pkg/analysis_server/test/protocol_server_test.dart
index 850b29a..4320775 100644
--- a/pkg/analysis_server/test/protocol_server_test.dart
+++ b/pkg/analysis_server/test/protocol_server_test.dart
@@ -360,7 +360,7 @@
Map<String, FileResult> fileResults = {};
void addFileResult(FileResult result) {
- fileResults[result.path!] = result;
+ fileResults[result.path] = result;
}
@override
diff --git a/pkg/analyzer/lib/dart/analysis/results.dart b/pkg/analyzer/lib/dart/analysis/results.dart
index 4a17594..6c36a21 100644
--- a/pkg/analyzer/lib/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/dart/analysis/results.dart
@@ -17,9 +17,7 @@
abstract class AnalysisResult {
/// The absolute and normalized path of the file that was analyzed.
/// If [state] is not [ResultState.VALID], throws [StateError].
- ///
- /// TODO(migration): should not be nullable
- String? get path;
+ String get path;
/// Return the session used to compute this result.
/// If [state] is not [ResultState.VALID], throws [StateError].
@@ -86,13 +84,13 @@
/// Clients may not extend, implement or mix-in this class.
abstract class ParsedLibraryResult implements AnalysisResult {
/// The parsed units of the library.
- ///
- /// TODO(migration): should not be null, probably empty list
- List<ParsedUnitResult>? get units;
+ /// If [state] is not [ResultState.VALID], throws [StateError].
+ List<ParsedUnitResult> get units;
/// Return the declaration of the [element], or `null` if the [element]
/// is synthetic. Throw [ArgumentError] if the [element] is not defined in
/// this library.
+ /// If [state] is not [ResultState.VALID], throws [StateError].
ElementDeclarationResult? getElementDeclaration(Element element);
}
@@ -134,17 +132,21 @@
/// Clients may not extend, implement or mix-in this class.
abstract class ResolvedLibraryResult implements AnalysisResult {
/// The element representing this library.
- LibraryElement? get element;
+ /// If [state] is not [ResultState.VALID], throws [StateError].
+ LibraryElement get element;
/// The type provider used when resolving the library.
+ /// If [state] is not [ResultState.VALID], throws [StateError].
TypeProvider get typeProvider;
/// The resolved units of the library.
- List<ResolvedUnitResult>? get units;
+ /// If [state] is not [ResultState.VALID], throws [StateError].
+ List<ResolvedUnitResult> get units;
/// Return the declaration of the [element], or `null` if the [element]
/// is synthetic. Throw [ArgumentError] if the [element] is not defined in
/// this library.
+ /// If [state] is not [ResultState.VALID], throws [StateError].
ElementDeclarationResult? getElementDeclaration(Element element);
}
@@ -171,6 +173,10 @@
/// An indication of whether an analysis result is valid, and if not why.
enum ResultState {
+ /// An indication that the analysis result cannot be provided because
+ /// the library is created from summary.
+ EXTERNAL_LIBRARY,
+
/// An indication that analysis could not be performed because the path
/// represents a file of a type that cannot be analyzed.
INVALID_FILE_TYPE,
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 8f17b48..75f297c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -215,7 +215,7 @@
final _resultController = StreamController<ResolvedUnitResult>();
/// The stream that will be written to when analysis results are produced.
- late final Stream<ResolvedUnitResult> _onResults;
+ late final Stream<ResolvedUnitResult> _resultStream;
/// Resolution signatures of the most recently produced results for files.
final Map<String, String> _lastProducedSignatures = {};
@@ -282,7 +282,7 @@
_externalSummaries = externalSummaries,
testingData = retainDataForTesting ? TestingData() : null {
_createNewSession(null);
- _onResults = _resultController.stream.asBroadcastStream();
+ _resultStream = _resultController.stream.asBroadcastStream();
_testView = AnalysisDriverTestView(this);
_createFileTracker();
_scheduler.add(this);
@@ -361,7 +361,7 @@
///
/// Results might be produced even for files that have never been added
/// using [addFile], for example when [getResult] was called for a file.
- Stream<ResolvedUnitResult> get results => _onResults;
+ Stream<ResolvedUnitResult> get results => _resultStream;
/// Return the search support for the driver.
Search get search => _search;
@@ -649,7 +649,7 @@
FileState file = _fsState.getFileForPath(path);
if (file.isExternalLibrary) {
- return ParsedLibraryResultImpl.external(currentSession, file.uri);
+ return NotValidParsedLibraryResultImpl(ResultState.EXTERNAL_LIBRARY);
}
if (file.isPart) {
@@ -680,7 +680,7 @@
}
if (file.isExternalLibrary) {
- return ParsedLibraryResultImpl.external(currentSession, file.uri);
+ return NotValidParsedLibraryResultImpl(ResultState.EXTERNAL_LIBRARY);
}
if (file.isPart) {
@@ -718,7 +718,7 @@
if (file.isExternalLibrary) {
return Future.value(
- ResolvedLibraryResultImpl.external(currentSession, file.uri),
+ NotValidResolvedLibraryResultImpl(ResultState.EXTERNAL_LIBRARY),
);
}
@@ -756,7 +756,7 @@
if (file.isExternalLibrary) {
return Future.value(
- ResolvedLibraryResultImpl.external(currentSession, file.uri),
+ NotValidResolvedLibraryResultImpl(ResultState.EXTERNAL_LIBRARY),
);
}
@@ -1102,7 +1102,7 @@
// last time, so we don't need to produce it again now.
} else {
_resultController.add(result);
- _lastProducedSignatures[result.path!] = result._signature;
+ _lastProducedSignatures[result.path] = result._signature;
}
} catch (exception, stackTrace) {
_reportException(path, exception, stackTrace);
diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart
index c2e5b28..1f4ded0 100644
--- a/pkg/analyzer/lib/src/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/results.dart
@@ -18,7 +18,7 @@
final AnalysisSession session;
@override
- final String? path;
+ final String path;
@override
final Uri uri;
@@ -75,7 +75,7 @@
NotValidAnalysisResultImpl(this.state);
@override
- String? get path {
+ String get path {
throw StateError('This result is not valid');
}
@@ -117,6 +117,46 @@
}
}
+class NotValidParsedLibraryResultImpl extends NotValidAnalysisResultImpl
+ implements ParsedLibraryResult {
+ NotValidParsedLibraryResultImpl(ResultState state) : super(state);
+
+ @override
+ List<ParsedUnitResult> get units {
+ throw StateError('This result is not valid');
+ }
+
+ @override
+ ElementDeclarationResult? getElementDeclaration(Element element) {
+ throw StateError('This result is not valid');
+ }
+}
+
+class NotValidResolvedLibraryResultImpl extends NotValidAnalysisResultImpl
+ implements ResolvedLibraryResult {
+ NotValidResolvedLibraryResultImpl(ResultState state) : super(state);
+
+ @override
+ LibraryElement get element {
+ throw StateError('This result is not valid');
+ }
+
+ @override
+ TypeProvider get typeProvider {
+ throw StateError('This result is not valid');
+ }
+
+ @override
+ List<ResolvedUnitResult> get units {
+ throw StateError('This result is not valid');
+ }
+
+ @override
+ ElementDeclarationResult? getElementDeclaration(Element element) {
+ throw StateError('This result is not valid');
+ }
+}
+
/// The implementation of [ResolvedUnitResult] when not [ResultState.VALID].
class NotValidResolvedUnitResultImpl extends NotValidFileResultImpl
implements ResolvedUnitResult {
@@ -172,20 +212,14 @@
class ParsedLibraryResultImpl extends AnalysisResultImpl
implements ParsedLibraryResult {
@override
- final List<ParsedUnitResult>? units;
+ final List<ParsedUnitResult> units;
ParsedLibraryResultImpl(
- AnalysisSession session, String? path, Uri uri, this.units)
+ AnalysisSession session, String path, Uri uri, this.units)
: super(session, path, uri);
- ParsedLibraryResultImpl.external(AnalysisSession session, Uri uri)
- : this(session, null, uri, null);
-
@override
ResultState get state {
- if (path == null) {
- return ResultState.NOT_A_FILE;
- }
return ResultState.VALID;
}
@@ -203,7 +237,7 @@
}
var elementPath = element.source!.fullName;
- var unitResult = units!.firstWhere(
+ var unitResult = units.firstWhere(
(r) => r.path == elementPath,
orElse: () {
var elementStr = element.getDisplayString(withNullability: true);
@@ -261,28 +295,22 @@
class ResolvedLibraryResultImpl extends AnalysisResultImpl
implements ResolvedLibraryResult {
@override
- final LibraryElement? element;
+ final LibraryElement element;
@override
- final List<ResolvedUnitResult>? units;
+ final List<ResolvedUnitResult> units;
ResolvedLibraryResultImpl(
- AnalysisSession session, String? path, Uri uri, this.element, this.units)
+ AnalysisSession session, String path, Uri uri, this.element, this.units)
: super(session, path, uri);
- ResolvedLibraryResultImpl.external(AnalysisSession session, Uri uri)
- : this(session, null, uri, null, null);
-
@override
ResultState get state {
- if (path == null) {
- return ResultState.NOT_A_FILE;
- }
return ResultState.VALID;
}
@override
- TypeProvider get typeProvider => element!.typeProvider;
+ TypeProvider get typeProvider => element.typeProvider;
@override
ElementDeclarationResult? getElementDeclaration(Element element) {
@@ -298,7 +326,7 @@
}
var elementPath = element.source!.fullName;
- var unitResult = units!.firstWhere(
+ var unitResult = units.firstWhere(
(r) => r.path == elementPath,
orElse: () {
var elementStr = element.getDisplayString(withNullability: true);
@@ -307,7 +335,7 @@
buffer.writeln(' is not defined in this library.');
// TODO(scheglov) https://github.com/dart-lang/sdk/issues/45430
buffer.writeln('elementPath: $elementPath');
- buffer.writeln('unitPaths: ${units!.map((e) => e.path).toList()}');
+ buffer.writeln('unitPaths: ${units.map((e) => e.path).toList()}');
throw ArgumentError('$buffer');
},
);
diff --git a/pkg/analyzer/lib/src/dart/analysis/session_helper.dart b/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
index 235e67d..d65da13 100644
--- a/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/session_helper.dart
@@ -54,7 +54,7 @@
var resolvedLibrary = await _getResolvedLibrary(libraryPath);
var unitPath = element.source!.fullName;
- return resolvedLibrary.units!.singleWhere((resolvedUnit) {
+ return resolvedLibrary.units.singleWhere((resolvedUnit) {
return resolvedUnit.path == unitPath;
});
}
diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
index e7dff9b..fb17e85 100644
--- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
+++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
@@ -398,7 +398,7 @@
performance: performance,
);
var result =
- libraryUnit.units!.firstWhere((element) => element.path == path);
+ libraryUnit.units.firstWhere((element) => element.path == path);
return result;
});
}
diff --git a/pkg/analyzer/test/generated/constant_test.dart b/pkg/analyzer/test/generated/constant_test.dart
index 5b8847d..c285f9b 100644
--- a/pkg/analyzer/test/generated/constant_test.dart
+++ b/pkg/analyzer/test/generated/constant_test.dart
@@ -497,7 +497,7 @@
var expression = findNode.variableDeclaration('x =').initializer!;
- var file = getFile(result.path!);
+ var file = getFile(result.path);
var evaluator = ConstantEvaluator(
file.createSource(result.uri),
result.libraryElement as LibraryElementImpl,
diff --git a/pkg/analyzer/test/src/dart/analysis/dependency/base.dart b/pkg/analyzer/test/src/dart/analysis/dependency/base.dart
index 3eec88f..978ea99 100644
--- a/pkg/analyzer/test/src/dart/analysis/dependency/base.dart
+++ b/pkg/analyzer/test/src/dart/analysis/dependency/base.dart
@@ -138,7 +138,7 @@
Future<List<CompilationUnit>> _resolveLibrary(String libraryPath) async {
var session = contextFor(libraryPath).currentSession;
var resolvedLibrary = await session.getResolvedLibrary(libraryPath);
- return resolvedLibrary.units!.map((ru) => ru.unit!).toList();
+ return resolvedLibrary.units.map((ru) => ru.unit!).toList();
}
}
diff --git a/pkg/analyzer/test/src/dart/analysis/driver_test.dart b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
index 9ddda1e..6572ba2 100644
--- a/pkg/analyzer/test/src/dart/analysis/driver_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/driver_test.dart
@@ -3063,7 +3063,7 @@
driver.changeFile(b);
await waitForIdleWithoutExceptions();
- List<String> analyzedPaths = allResults.map((r) => r.path!).toList();
+ List<String> analyzedPaths = allResults.map((r) => r.path).toList();
// The changed file must be the first.
expect(analyzedPaths[0], b);
@@ -3105,7 +3105,7 @@
driver.changeFile(a);
await waitForIdleWithoutExceptions();
- List<String> analyzedPaths = allResults.map((r) => r.path!).toList();
+ List<String> analyzedPaths = allResults.map((r) => r.path).toList();
// The changed files must be the first.
expect(analyzedPaths[0], a);
diff --git a/pkg/analyzer/test/src/dart/analysis/session_test.dart b/pkg/analyzer/test/src/dart/analysis/session_test.dart
index f1235ca..c32728a 100644
--- a/pkg/analyzer/test/src/dart/analysis/session_test.dart
+++ b/pkg/analyzer/test/src/dart/analysis/session_test.dart
@@ -175,7 +175,7 @@
expect(parsedLibrary.units, hasLength(1));
{
- var parsedUnit = parsedLibrary.units![0];
+ var parsedUnit = parsedLibrary.units[0];
expect(parsedUnit.session, session);
expect(parsedUnit.path, testPath);
expect(parsedUnit.uri, Uri.parse('package:test/test.dart'));
@@ -249,15 +249,15 @@
expect(parsedLibrary.units, hasLength(3));
expect(
- parsedLibrary.units![0].path,
+ parsedLibrary.units[0].path,
convertPath('/home/test/lib/test.dart'),
);
expect(
- parsedLibrary.units![1].path,
+ parsedLibrary.units[1].path,
convertPath('/home/test/lib/a.dart'),
);
expect(
- parsedLibrary.units![2].path,
+ parsedLibrary.units[2].path,
convertPath('/home/test/lib/c.dart'),
);
}
@@ -307,21 +307,21 @@
expect(parsedLibrary.units, hasLength(3));
{
- var aUnit = parsedLibrary.units![0];
+ var aUnit = parsedLibrary.units[0];
expect(aUnit.path, a);
expect(aUnit.uri, Uri.parse('package:test/a.dart'));
expect(aUnit.unit.declarations, hasLength(1));
}
{
- var bUnit = parsedLibrary.units![1];
+ var bUnit = parsedLibrary.units[1];
expect(bUnit.path, b);
expect(bUnit.uri, Uri.parse('package:test/b.dart'));
expect(bUnit.unit.declarations, hasLength(2));
}
{
- var cUnit = parsedLibrary.units![2];
+ var cUnit = parsedLibrary.units[2];
expect(cUnit.path, c);
expect(cUnit.uri, Uri.parse('package:test/c.dart'));
expect(cUnit.unit.declarations, hasLength(3));
@@ -393,13 +393,13 @@
var typeProvider = resolvedLibrary.typeProvider;
expect(typeProvider.intType.element.name, 'int');
- var libraryElement = resolvedLibrary.element!;
+ var libraryElement = resolvedLibrary.element;
var aClass = libraryElement.getType('A')!;
var bClass = libraryElement.getType('B')!;
- var aUnitResult = resolvedLibrary.units![0];
+ var aUnitResult = resolvedLibrary.units[0];
expect(aUnitResult.path, a);
expect(aUnitResult.uri, Uri.parse('package:test/a.dart'));
expect(aUnitResult.content, aContent);
@@ -408,7 +408,7 @@
expect(aUnitResult.unit!.declarations, hasLength(1));
expect(aUnitResult.errors, isEmpty);
- var bUnitResult = resolvedLibrary.units![1];
+ var bUnitResult = resolvedLibrary.units[1];
expect(bUnitResult.path, b);
expect(bUnitResult.uri, Uri.parse('package:test/b.dart'));
expect(bUnitResult.content, bContent);
@@ -449,7 +449,7 @@
''');
var resolvedLibrary = await session.getResolvedLibrary(testPath);
- var unitElement = resolvedLibrary.element!.definingCompilationUnit;
+ var unitElement = resolvedLibrary.element.definingCompilationUnit;
var fooElement = unitElement.topLevelVariables[0];
expect(fooElement.name, 'foo');
@@ -478,15 +478,15 @@
expect(resolvedLibrary.units, hasLength(3));
expect(
- resolvedLibrary.units![0].path,
+ resolvedLibrary.units[0].path,
convertPath('/home/test/lib/test.dart'),
);
expect(
- resolvedLibrary.units![1].path,
+ resolvedLibrary.units[1].path,
convertPath('/home/test/lib/a.dart'),
);
expect(
- resolvedLibrary.units![2].path,
+ resolvedLibrary.units[2].path,
convertPath('/home/test/lib/c.dart'),
);
}
@@ -509,7 +509,7 @@
expect(resolvedLibrary.path, testPath);
expect(resolvedLibrary.uri, Uri.parse('package:test/test.dart'));
expect(resolvedLibrary.units, hasLength(1));
- expect(resolvedLibrary.units![0].unit!.declaredElement, isNotNull);
+ expect(resolvedLibrary.units[0].unit!.declaredElement, isNotNull);
}
test_getResolvedLibraryByElement_differentSession() async {
diff --git a/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart b/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
index aa6dfb3..54c65b5 100644
--- a/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
+++ b/pkg/analyzer/test/src/dart/micro/simple_file_resolver_test.dart
@@ -700,7 +700,7 @@
var result = fileResolver.resolveLibrary(path: aPath);
expect(result.path, aPath);
- expect(result.units?.length, 2);
+ expect(result.units.length, 2);
}
test_reuse_compatibleOptions() async {
diff --git a/pkg/analyzer/test/verify_diagnostics_test.dart b/pkg/analyzer/test/verify_diagnostics_test.dart
index f99f600..8fdbc40 100644
--- a/pkg/analyzer/test/verify_diagnostics_test.dart
+++ b/pkg/analyzer/test/verify_diagnostics_test.dart
@@ -285,7 +285,7 @@
/// Extract documentation from the file that was parsed to produce the given
/// [result].
Future<void> _validateFile(ParsedUnitResult result) async {
- filePath = result.path!;
+ filePath = result.path;
hasWrittenFilePath = false;
CompilationUnit unit = result.unit;
for (CompilationUnitMember declaration in unit.declarations) {
diff --git a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
index 443c711..dc60a78 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/change_builder/change_builder_dart.dart
@@ -1281,7 +1281,7 @@
/// the given [resolvedUnit] and [timeStamp].
DartFileEditBuilderImpl(ChangeBuilderImpl changeBuilder, this.resolvedUnit,
int timeStamp, this.libraryChangeBuilder)
- : super(changeBuilder, resolvedUnit.path!, timeStamp);
+ : super(changeBuilder, resolvedUnit.path, timeStamp);
@override
bool get hasEdits =>
diff --git a/pkg/analyzer_plugin/lib/src/utilities/folding/folding.dart b/pkg/analyzer_plugin/lib/src/utilities/folding/folding.dart
index a302a76..d424abf 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/folding/folding.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/folding/folding.dart
@@ -21,7 +21,7 @@
DartFoldingRequestImpl(this.resourceProvider, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [FoldingCollector].
diff --git a/pkg/analyzer_plugin/lib/src/utilities/highlights/highlights.dart b/pkg/analyzer_plugin/lib/src/utilities/highlights/highlights.dart
index 5e55b48..95bd889 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/highlights/highlights.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/highlights/highlights.dart
@@ -21,7 +21,7 @@
DartHighlightsRequestImpl(this.resourceProvider, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [HighlightsCollector].
diff --git a/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart b/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart
index 191101c..684e9e7 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/kythe/entries.dart
@@ -19,7 +19,7 @@
DartEntryRequestImpl(this.resourceProvider, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [EntryCollector].
diff --git a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation.dart b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation.dart
index 4e1850c..23709a3 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/navigation/navigation.dart
@@ -28,7 +28,7 @@
this.resourceProvider, this.offset, this.length, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [NavigationCollector].
diff --git a/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart b/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
index 6bd0592..f436774 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/occurrences/occurrences.dart
@@ -20,7 +20,7 @@
DartOccurrencesRequestImpl(this.resourceProvider, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [OccurrencesCollector].
diff --git a/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart b/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
index 44d4dd9..284f140 100644
--- a/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
+++ b/pkg/analyzer_plugin/lib/src/utilities/outline/outline.dart
@@ -20,7 +20,7 @@
DartOutlineRequestImpl(this.resourceProvider, this.result);
@override
- String get path => result.path!;
+ String get path => result.path;
}
/// A concrete implementation of [OutlineCollector].