mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
Make AnalysisResult.path non-nullable.
Change-Id: I861643f6c5493b6990c0bacddd81643aaba8e368 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206560 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
parent
b3fb8c55e5
commit
672d66cea0
|
@ -679,7 +679,7 @@ class ServerContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
@override
|
||||
void listenAnalysisDriver(analysis.AnalysisDriver analysisDriver) {
|
||||
analysisDriver.results.listen((result) {
|
||||
var path = result.path!;
|
||||
var path = result.path;
|
||||
filesToFlush.add(path);
|
||||
if (analysisServer.isAnalyzed(path)) {
|
||||
_notificationManager.recordAnalysisErrors(NotificationManager.serverId,
|
||||
|
|
|
@ -87,9 +87,6 @@ class DartUnitOutlineComputer {
|
|||
|
||||
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;
|
||||
|
|
|
@ -32,8 +32,7 @@ class ImportElementsComputer {
|
|||
Future<SourceChange> createEdits(
|
||||
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('');
|
||||
|
@ -50,7 +49,7 @@ class ImportElementsComputer {
|
|||
}
|
||||
|
||||
var builder = ChangeBuilder(session: libraryResult.session);
|
||||
await builder.addDartFileEdit(path, (builder) {
|
||||
await builder.addDartFileEdit(libraryResult.path, (builder) {
|
||||
for (var importedElements in filteredImportedElements) {
|
||||
var matchingImports =
|
||||
_findMatchingImports(existingImports, importedElements);
|
||||
|
|
|
@ -24,7 +24,7 @@ void computeIncludedSetList(
|
|||
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)
|
||||
|
|
|
@ -611,7 +611,7 @@ class EditDomainHandler extends AbstractRequestHandler {
|
|||
var provider = TopLevelDeclarationsProvider(tracker);
|
||||
return provider.get(
|
||||
result.session.analysisContext,
|
||||
result.path!,
|
||||
result.path,
|
||||
name,
|
||||
);
|
||||
}, extensionCache: server.getExtensionCacheFor(result));
|
||||
|
|
|
@ -15,7 +15,7 @@ void sendFlutterNotificationOutline(
|
|||
var outline = computer.compute();
|
||||
// send notification
|
||||
var params = protocol.FlutterOutlineParams(
|
||||
resolvedUnit.path!,
|
||||
resolvedUnit.path,
|
||||
outline,
|
||||
);
|
||||
server.sendNotification(params.toNotification());
|
||||
|
|
|
@ -309,7 +309,7 @@ class CodeActionHandler extends MessageHandler<CodeActionParams,
|
|||
var tracker = server.declarationsTracker!;
|
||||
return TopLevelDeclarationsProvider(tracker).get(
|
||||
unit.session.analysisContext,
|
||||
unit.path!,
|
||||
unit.path,
|
||||
name,
|
||||
);
|
||||
}, extensionCache: server.getExtensionCacheFor(unit));
|
||||
|
|
|
@ -374,7 +374,7 @@ class CompletionHandler
|
|||
importingUris.first == '${library.uri}';
|
||||
}).map((item) => declarationToCompletionItem(
|
||||
capabilities,
|
||||
unit.path!,
|
||||
unit.path,
|
||||
offset,
|
||||
includedSet,
|
||||
library,
|
||||
|
|
|
@ -826,11 +826,6 @@ class LspServerContextManagerCallbacks extends ContextManagerCallbacks {
|
|||
|
||||
analysisDriver.results.listen((result) {
|
||||
var path = result.path;
|
||||
if (path == null) {
|
||||
// This shouldn't occur - result.path is marked with a TODO to become
|
||||
// non-nullable.
|
||||
return;
|
||||
}
|
||||
filesToFlush.add(path);
|
||||
if (analysisServer.isAnalyzed(path)) {
|
||||
final serverErrors = protocol.doAnalysisError_listFromEngine(result);
|
||||
|
|
|
@ -112,7 +112,7 @@ void sendAnalysisNotificationOutline(
|
|||
|
||||
// send notification
|
||||
var params = protocol.AnalysisOutlineParams(
|
||||
resolvedUnit.path!, fileKind, outline,
|
||||
resolvedUnit.path, fileKind, outline,
|
||||
libraryName: libraryName);
|
||||
server.sendNotification(params.toNotification());
|
||||
});
|
||||
|
|
|
@ -100,7 +100,7 @@ class DartCompletionManager {
|
|||
}) 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>[];
|
||||
}
|
||||
|
||||
|
|
|
@ -704,7 +704,7 @@ class SuggestionBuilder {
|
|||
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,
|
||||
|
|
|
@ -264,7 +264,7 @@ class PostfixCompletionProcessor {
|
|||
|
||||
String get eol => utils.endOfLine;
|
||||
|
||||
String get file => completionContext.resolveResult.path!;
|
||||
String get file => completionContext.resolveResult.path;
|
||||
|
||||
String get key => completionContext.key;
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ class StatementCompletionProcessor {
|
|||
|
||||
String get eol => utils.endOfLine;
|
||||
|
||||
String get file => statementContext.resolveResult.path!;
|
||||
String get file => statementContext.resolveResult.path;
|
||||
|
||||
LineInfo get lineInfo => statementContext.resolveResult.lineInfo;
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ abstract class BaseProcessor {
|
|||
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,
|
||||
|
|
|
@ -336,7 +336,7 @@ class BulkFixProcessor {
|
|||
await compute(producer);
|
||||
var newHash = computeChangeHash();
|
||||
if (newHash != oldHash) {
|
||||
changeMap.add(result.path!, code);
|
||||
changeMap.add(result.path, code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -401,7 +401,7 @@ class BulkFixProcessor {
|
|||
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 {
|
||||
|
|
|
@ -249,7 +249,7 @@ class CorrectionProducerContext {
|
|||
this.overrideSet,
|
||||
this.selectionOffset = -1,
|
||||
this.selectionLength = 0,
|
||||
}) : file = resolvedResult.path!,
|
||||
}) : file = resolvedResult.path,
|
||||
session = resolvedResult.session,
|
||||
sessionHelper = AnalysisSessionHelper(resolvedResult.session),
|
||||
typeProvider = resolvedResult.typeProvider,
|
||||
|
|
|
@ -27,7 +27,7 @@ class ConvertPartOfToUri extends CorrectionProducer {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -118,7 +118,7 @@ class PropertyDescription {
|
|||
);
|
||||
}
|
||||
|
||||
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 @@ class PropertyDescription {
|
|||
}
|
||||
|
||||
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 @@ class _EdgeInsetsProperty {
|
|||
|
||||
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);
|
||||
|
|
|
@ -61,7 +61,7 @@ class ExtractLocalRefactoringImpl extends RefactoringImpl
|
|||
utils = CorrectionUtils(resolveResult);
|
||||
}
|
||||
|
||||
String get file => resolveResult.path!;
|
||||
String get file => resolveResult.path;
|
||||
|
||||
@override
|
||||
String get refactoringName => 'Extract Local Variable';
|
||||
|
|
|
@ -144,7 +144,7 @@ class ExtractWidgetRefactoringImpl extends RefactoringImpl
|
|||
Future<SourceChange> createChange() async {
|
||||
var builder =
|
||||
ChangeBuilder(session: sessionHelper.session, eol: utils.endOfLine);
|
||||
await builder.addDartFileEdit(resolveResult.path!, (builder) {
|
||||
await builder.addDartFileEdit(resolveResult.path, (builder) {
|
||||
final expression = _expression;
|
||||
final statements = _statements;
|
||||
if (expression != null) {
|
||||
|
|
|
@ -113,8 +113,7 @@ class MoveFileRefactoringImpl extends RefactoringImpl
|
|||
}
|
||||
|
||||
if (newDir != oldDir) {
|
||||
await changeBuilder.addDartFileEdit(definingUnitResult.path!,
|
||||
(builder) {
|
||||
await changeBuilder.addDartFileEdit(definingUnitResult.path, (builder) {
|
||||
for (var directive in definingUnitResult.unit!.directives) {
|
||||
if (directive is UriBasedDirective) {
|
||||
_updateUriReference(builder, directive, oldDir, newDir);
|
||||
|
|
|
@ -361,7 +361,7 @@ class MockAnalysisSession implements AnalysisSession {
|
|||
Map<String, FileResult> fileResults = {};
|
||||
|
||||
void addFileResult(FileResult result) {
|
||||
fileResults[result.path!] = result;
|
||||
fileResults[result.path] = result;
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -1315,7 +1315,7 @@ class CompletionMetricsComputer {
|
|||
}
|
||||
for (var result in results) {
|
||||
_resolvedUnitResult = result;
|
||||
var filePath = result.path!;
|
||||
var filePath = result.path;
|
||||
// Use the ExpectedCompletionsVisitor to compute the set of expected
|
||||
// completions for this CompilationUnit.
|
||||
final visitor = ExpectedCompletionsVisitor(filePath);
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
## 2.1.0
|
||||
* Changed `AnalysisResult.path` to be non-nullable.
|
||||
|
||||
## 2.0.0
|
||||
* Removed deprecated `Scope.lookup2()`.
|
||||
* Removed deprecated setters in API of AST.
|
||||
|
|
|
@ -17,9 +17,7 @@ import 'package:analyzer/src/generated/source.dart';
|
|||
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].
|
||||
|
|
|
@ -1148,7 +1148,7 @@ class AnalysisDriver implements AnalysisDriverGeneric {
|
|||
// 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);
|
||||
|
|
|
@ -17,7 +17,7 @@ abstract class AnalysisResultImpl implements AnalysisResult {
|
|||
final AnalysisSession session;
|
||||
|
||||
@override
|
||||
final String? path;
|
||||
final String path;
|
||||
|
||||
@override
|
||||
final Uri uri;
|
||||
|
@ -79,14 +79,11 @@ class ParsedLibraryResultImpl extends AnalysisResultImpl
|
|||
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);
|
||||
|
||||
@override
|
||||
ResultState get state {
|
||||
if (path == null) {
|
||||
return ResultState.NOT_A_FILE;
|
||||
}
|
||||
return ResultState.VALID;
|
||||
}
|
||||
|
||||
|
@ -168,14 +165,11 @@ class ResolvedLibraryResultImpl extends AnalysisResultImpl
|
|||
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);
|
||||
|
||||
@override
|
||||
ResultState get state {
|
||||
if (path == null) {
|
||||
return ResultState.NOT_A_FILE;
|
||||
}
|
||||
return ResultState.VALID;
|
||||
}
|
||||
|
||||
|
|
|
@ -497,7 +497,7 @@ $context
|
|||
|
||||
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,
|
||||
|
|
|
@ -3028,7 +3028,7 @@ class F extends X {}
|
|||
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);
|
||||
|
@ -3070,7 +3070,7 @@ class F extends X {}
|
|||
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);
|
||||
|
|
|
@ -1007,7 +1007,7 @@ void func() {
|
|||
}
|
||||
''');
|
||||
|
||||
_assertDiscoveredLibraryForParts([result.path!]);
|
||||
_assertDiscoveredLibraryForParts([result.path]);
|
||||
}
|
||||
|
||||
test_resolve_part_of_uri() async {
|
||||
|
@ -1028,7 +1028,7 @@ void func() {
|
|||
}
|
||||
''');
|
||||
|
||||
_assertDiscoveredLibraryForParts([result.path!]);
|
||||
_assertDiscoveredLibraryForParts([result.path]);
|
||||
}
|
||||
|
||||
test_resolveFile_cache() async {
|
||||
|
|
|
@ -321,7 +321,7 @@ class DocumentationValidator {
|
|||
/// 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) {
|
||||
|
|
|
@ -1281,7 +1281,7 @@ class DartFileEditBuilderImpl extends FileEditBuilderImpl
|
|||
/// 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 =>
|
||||
|
|
|
@ -21,7 +21,7 @@ class DartFoldingRequestImpl implements DartFoldingRequest {
|
|||
DartFoldingRequestImpl(this.resourceProvider, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [FoldingCollector].
|
||||
|
|
|
@ -21,7 +21,7 @@ class DartHighlightsRequestImpl implements DartHighlightsRequest {
|
|||
DartHighlightsRequestImpl(this.resourceProvider, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [HighlightsCollector].
|
||||
|
|
|
@ -19,7 +19,7 @@ class DartEntryRequestImpl implements DartEntryRequest {
|
|||
DartEntryRequestImpl(this.resourceProvider, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [EntryCollector].
|
||||
|
|
|
@ -28,7 +28,7 @@ class DartNavigationRequestImpl implements DartNavigationRequest {
|
|||
this.resourceProvider, this.offset, this.length, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [NavigationCollector].
|
||||
|
|
|
@ -20,7 +20,7 @@ class DartOccurrencesRequestImpl implements DartOccurrencesRequest {
|
|||
DartOccurrencesRequestImpl(this.resourceProvider, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [OccurrencesCollector].
|
||||
|
|
|
@ -20,7 +20,7 @@ class DartOutlineRequestImpl implements DartOutlineRequest {
|
|||
DartOutlineRequestImpl(this.resourceProvider, this.result);
|
||||
|
||||
@override
|
||||
String get path => result.path!;
|
||||
String get path => result.path;
|
||||
}
|
||||
|
||||
/// A concrete implementation of [OutlineCollector].
|
||||
|
|
|
@ -1093,7 +1093,7 @@ class _FixCodeProcessor extends Object {
|
|||
});
|
||||
await processResources((ResolvedUnitResult result) async {
|
||||
_progressBar.tick();
|
||||
if (_migrationCli.shouldBeMigrated(result.path!)) {
|
||||
if (_migrationCli.shouldBeMigrated(result.path)) {
|
||||
await _task!.finalizeUnit(result);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -111,7 +111,7 @@ class InfoBuilder {
|
|||
// referenced (we'll just skip the entire library because we'll only
|
||||
// ever see its parts).
|
||||
sourceInfo ??= SourceInformation();
|
||||
var edit = listener!.sourceChange.getFileEdit(unitResult.path!);
|
||||
var edit = listener!.sourceChange.getFileEdit(unitResult.path);
|
||||
var unit = _explainUnit(sourceInfo, unitResult, edit);
|
||||
if (_pathsToProcess!.contains(unitResult.path)) {
|
||||
units.add(unit);
|
||||
|
|
Loading…
Reference in a new issue