Revert "add a `file` property to `FileResult`s"
This reverts commit 18c8a50557d9da0d106fe0f77f9ce3dd488968d1.
Reason for revert: windows path-related test failures
Original change's description:
> add a `file` property to `FileResult`s
>
> Change-Id: Ibec62da4552da3124d85f6020f4e8e1dac8a757b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333588
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
> Commit-Queue: Phil Quitslund <pquitslund@google.com>
> Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Change-Id: I0eea9e0a40b0c2a65795013fca129a03b3759e37
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334281
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Auto-Submit: Phil Quitslund <pquitslund@google.com>
diff --git a/pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart b/pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart
index 104f363..387b9fd 100644
--- a/pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart
+++ b/pkg/analysis_server/lib/src/handler/legacy/edit_get_fixes.dart
@@ -123,8 +123,8 @@
var lineInfo = LineInfo.fromContent(content);
var result = engine.ErrorsResultImpl(
session: session,
- file: optionsFile,
- uri: optionsFile.toUri(),
+ path: file,
+ uri: Uri.file(file),
lineInfo: lineInfo,
isAugmentation: false,
isLibrary: true,
@@ -232,13 +232,10 @@
if (fixes.isNotEmpty) {
fixes.sort(Fix.compareFixes);
var lineInfo = LineInfo.fromContent(content);
- // TODO(pq) package:analyzer results are specific to *.dart files and we
- // shouldn't use them to represent errors in non-Dart files.
- // see: https://dart-review.googlesource.com/c/sdk/+/333588
var result = engine.ErrorsResultImpl(
session: session,
- file: pubspecFile,
- uri: pubspecFile.toUri(),
+ path: file,
+ uri: Uri.file(file),
lineInfo: lineInfo,
isAugmentation: false,
isLibrary: true,
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart
index 44168ce..d6e595d 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/abstract_code_actions_producer.dart
@@ -29,7 +29,7 @@
/// A base for classes that produce [CodeAction]s for the LSP handler.
abstract class AbstractCodeActionsProducer
with RequestHandlerMixin<LspAnalysisServer> {
- final File file;
+ final String path;
final LineInfo lineInfo;
final int offset;
final int length;
@@ -41,7 +41,7 @@
AbstractCodeActionsProducer(
this.server,
- this.file,
+ this.path,
this.lineInfo, {
required this.offset,
required this.length,
@@ -51,8 +51,6 @@
String get name;
- String get path => file.path;
-
Set<DiagnosticTag> get supportedDiagnosticTags => capabilities.diagnosticTags;
bool get supportsApplyEdit => capabilities.applyEdit;
@@ -132,7 +130,7 @@
AnalysisSession session, LineInfo lineInfo, List<AnalysisError> errors) {
return engine.ErrorsResultImpl(
session: session,
- file: file,
+ path: path,
uri: server.pathContext.toUri(path),
lineInfo: lineInfo,
isAugmentation: false,
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart
index e1ff304..5b216c5 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/analysis_options.dart
@@ -16,7 +16,7 @@
class AnalysisOptionsCodeActionsProducer extends AbstractCodeActionsProducer {
AnalysisOptionsCodeActionsProducer(
super.server,
- super.file,
+ super.path,
super.lineInfo, {
required super.offset,
required super.length,
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
index 2b5ff0b..e701f44 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/dart.dart
@@ -34,7 +34,7 @@
DartCodeActionsProducer(
super.server,
- super.file,
+ super.path,
super.lineInfo,
this.docIdentifier,
this.library,
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart
index 3049602..aea7eab 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/plugins.dart
@@ -18,13 +18,13 @@
PluginCodeActionsProducer(
super.server,
- super.file,
+ super.path,
super.lineInfo, {
required super.offset,
required super.length,
required super.shouldIncludeKind,
required super.capabilities,
- }) : driver = server.getAnalysisDriver(file.path);
+ }) : driver = server.getAnalysisDriver(path);
@override
String get name => 'PluginActionsComputer';
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart
index 19ad935..08db336 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/code_actions/pubspec.dart
@@ -15,7 +15,7 @@
class PubspecCodeActionsProducer extends AbstractCodeActionsProducer {
PubspecCodeActionsProducer(
super.server,
- super.file,
+ super.path,
super.lineInfo, {
required super.offset,
required super.length,
diff --git a/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart b/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart
index a956dfa..0d340ca 100644
--- a/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart
+++ b/pkg/analysis_server/lib/src/lsp/handlers/handler_code_actions.dart
@@ -145,7 +145,7 @@
if (isDart && libraryResult != null && unit != null)
DartCodeActionsProducer(
server,
- unit.file,
+ unitPath,
lineInfo,
docIdentifier,
range: params.range,
@@ -160,8 +160,7 @@
if (isPubspec)
PubspecCodeActionsProducer(
server,
- // TODO(pq) can we do better?
- server.resourceProvider.getFile(unitPath),
+ unitPath,
lineInfo,
offset: offset,
length: length,
@@ -171,8 +170,7 @@
if (isAnalysisOptions)
AnalysisOptionsCodeActionsProducer(
server,
- // TODO(pq) can we do better?
- server.resourceProvider.getFile(unitPath),
+ unitPath,
lineInfo,
offset: offset,
length: length,
@@ -181,8 +179,7 @@
),
PluginCodeActionsProducer(
server,
- // TODO(pq) can we do better?
- server.resourceProvider.getFile(unitPath),
+ unitPath,
lineInfo,
offset: offset,
length: length,
diff --git a/pkg/analyzer/lib/dart/analysis/results.dart b/pkg/analyzer/lib/dart/analysis/results.dart
index 4d3e426..857b5a1 100644
--- a/pkg/analyzer/lib/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/dart/analysis/results.dart
@@ -8,7 +8,6 @@
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/dart/element/type_system.dart';
import 'package:analyzer/error/error.dart';
-import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/src/generated/source.dart';
/// The result of performing some kind of analysis on a single file. Every
@@ -84,9 +83,6 @@
///
/// Clients may not extend, implement or mix-in this class.
abstract class FileResult implements SomeFileResult, AnalysisResult {
- /// The file resource.
- File get file;
-
/// Whether the file is a library augmentation.
/// When `true`, [isLibrary] and [isPart] are `false`.
bool get isAugmentation;
diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart
index 8bfdb03..369711c 100644
--- a/pkg/analyzer/lib/src/dart/analysis/driver.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart
@@ -747,7 +747,12 @@
FileState file = _fsState.getFileForPath(path);
return FileResultImpl(
session: currentSession,
- fileState: file,
+ path: path,
+ uri: file.uri,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
);
}
@@ -1041,7 +1046,13 @@
CompilationUnit unit = file.parse(listener);
return ParsedUnitResultImpl(
session: currentSession,
- fileState: file,
+ path: file.path,
+ uri: file.uri,
+ content: file.content,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
unit: unit,
errors: listener.errors,
);
@@ -1529,7 +1540,12 @@
var element = libraryContext.computeUnitElement(library, file);
return UnitElementResultImpl(
session: currentSession,
- fileState: file,
+ path: path,
+ uri: file.uri,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
element: element,
);
});
@@ -1541,9 +1557,9 @@
}) {
return ErrorsResultImpl(
session: currentSession,
- file: file.resource,
- lineInfo: file.lineInfo,
+ path: file.path,
uri: file.uri,
+ lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
@@ -1595,8 +1611,14 @@
}) {
return ResolvedUnitResultImpl(
session: currentSession,
- fileState: file,
+ path: file.path,
+ uri: file.uri,
+ exists: file.exists,
content: file.content,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
unit: unitResult.unit,
errors: unitResult.errors,
);
@@ -1701,8 +1723,14 @@
if (content != null && resolvedUnit != null) {
var resolvedUnitResult = ResolvedUnitResultImpl(
session: currentSession,
- fileState: file,
+ path: file.path,
+ uri: file.uri,
+ exists: file.exists,
content: content,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
unit: resolvedUnit,
errors: errors,
);
@@ -1787,9 +1815,9 @@
// TODO(scheglov) Find a better way to report this.
var errorsResult = ErrorsResultImpl(
session: currentSession,
- file: file.resource,
- lineInfo: file.lineInfo,
+ path: file.path,
uri: file.uri,
+ lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
isLibrary: file.kind is LibraryFileKind,
isPart: file.kind is PartFileKind,
diff --git a/pkg/analyzer/lib/src/dart/analysis/results.dart b/pkg/analyzer/lib/src/dart/analysis/results.dart
index 046d101..4209bd8 100644
--- a/pkg/analyzer/lib/src/dart/analysis/results.dart
+++ b/pkg/analyzer/lib/src/dart/analysis/results.dart
@@ -10,9 +10,7 @@
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type_provider.dart';
import 'package:analyzer/error/error.dart';
-import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/source/line_info.dart';
-import 'package:analyzer/src/dart/analysis/file_state.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
abstract class AnalysisResultImpl implements AnalysisResult {
@@ -41,48 +39,28 @@
this.element, this.node, this.parsedUnit, this.resolvedUnit);
}
-class ErrorsResultImpl implements ErrorsResult {
+class ErrorsResultImpl extends FileResultImpl implements ErrorsResult {
@override
final List<AnalysisError> errors;
- @override
- final bool isAugmentation;
-
- @override
- final bool isLibrary;
-
- @override
- final bool isPart;
-
- @override
- final LineInfo lineInfo;
-
- @override
- final AnalysisSession session;
-
- @override
- final Uri uri;
-
- @override
- File file;
-
ErrorsResultImpl({
- required this.session,
- required this.file,
- required this.uri,
- required this.lineInfo,
- required this.isAugmentation,
- required this.isLibrary,
- required this.isPart,
+ required super.session,
+ required super.path,
+ required super.uri,
+ required super.lineInfo,
+ required super.isAugmentation,
+ required super.isLibrary,
+ required super.isPart,
required this.errors,
});
-
- @override
- String get path => file.path;
}
class FileResultImpl extends AnalysisResultImpl implements FileResult {
- final FileState fileState;
+ @override
+ final String path;
+
+ @override
+ final Uri uri;
@override
final LineInfo lineInfo;
@@ -98,20 +76,13 @@
FileResultImpl({
required super.session,
- required this.fileState,
- }) : lineInfo = fileState.lineInfo,
- isAugmentation = fileState.kind is AugmentationFileKind,
- isLibrary = fileState.kind is LibraryFileKind,
- isPart = fileState.kind is PartFileKind;
-
- @override
- File get file => fileState.resource;
-
- @override
- String get path => fileState.path;
-
- @override
- Uri get uri => fileState.uri;
+ required this.path,
+ required this.uri,
+ required this.lineInfo,
+ required this.isAugmentation,
+ required this.isLibrary,
+ required this.isPart,
+ });
}
class LibraryElementResultImpl implements LibraryElementResult {
@@ -174,10 +145,16 @@
ParsedUnitResultImpl({
required super.session,
- required super.fileState,
+ required super.path,
+ required super.uri,
+ required this.content,
+ required super.lineInfo,
+ required super.isAugmentation,
+ required super.isLibrary,
+ required super.isPart,
required this.unit,
required this.errors,
- }) : content = fileState.content;
+ });
}
class ParseStringResultImpl implements ParseStringResult {
@@ -301,6 +278,9 @@
class ResolvedUnitResultImpl extends FileResultImpl
implements ResolvedUnitResult {
@override
+ final bool exists;
+
+ @override
final String content;
@override
@@ -311,16 +291,19 @@
ResolvedUnitResultImpl({
required super.session,
- required super.fileState,
+ required super.path,
+ required super.uri,
+ required this.exists,
required this.content,
+ required super.lineInfo,
+ required super.isAugmentation,
+ required super.isLibrary,
+ required super.isPart,
required this.unit,
required this.errors,
});
@override
- bool get exists => fileState.exists;
-
- @override
LibraryElement get libraryElement {
return unit.declaredElement!.library;
}
@@ -339,7 +322,12 @@
UnitElementResultImpl({
required super.session,
- required super.fileState,
+ required super.path,
+ required super.uri,
+ required super.lineInfo,
+ required super.isAugmentation,
+ required super.isLibrary,
+ required super.isPart,
required this.element,
});
}
diff --git a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
index e73f612..0351e43 100644
--- a/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
+++ b/pkg/analyzer/lib/src/dart/micro/resolve_file.dart
@@ -350,7 +350,7 @@
return ErrorsResultImpl(
session: contextObjects!.analysisSession,
- file: file.resource,
+ path: path,
uri: file.uri,
lineInfo: file.lineInfo,
isAugmentation: file.kind is AugmentationFileKind,
@@ -670,8 +670,14 @@
var file = fileResult.file;
return ResolvedUnitResultImpl(
session: contextObjects!.analysisSession,
- fileState: file,
+ path: file.path,
+ uri: file.uri,
+ exists: file.exists,
content: file.content,
+ lineInfo: file.lineInfo,
+ isAugmentation: file.kind is AugmentationFileKind,
+ isLibrary: file.kind is LibraryFileKind,
+ isPart: file.kind is PartFileKind,
unit: fileResult.unit,
errors: fileResult.errors,
);
diff --git a/pkg/analyzer_cli/lib/src/driver.dart b/pkg/analyzer_cli/lib/src/driver.dart
index 06c4df4..7a32fe0 100644
--- a/pkg/analyzer_cli/lib/src/driver.dart
+++ b/pkg/analyzer_cli/lib/src/driver.dart
@@ -253,7 +253,7 @@
await formatter.formatErrors([
ErrorsResultImpl(
session: analysisDriver.currentSession,
- file: file,
+ path: path,
uri: pathContext.toUri(path),
lineInfo: lineInfo,
isAugmentation: false,
@@ -295,7 +295,7 @@
await formatter.formatErrors([
ErrorsResultImpl(
session: analysisDriver.currentSession,
- file: file,
+ path: path,
uri: pathContext.toUri(path),
lineInfo: lineInfo,
isAugmentation: false,
@@ -319,7 +319,7 @@
await formatter.formatErrors([
ErrorsResultImpl(
session: analysisDriver.currentSession,
- file: file,
+ path: path,
uri: pathContext.toUri(path),
lineInfo: lineInfo,
isAugmentation: false,
diff --git a/pkg/analyzer_cli/test/reporter_test.dart b/pkg/analyzer_cli/test/reporter_test.dart
index 1db2300..99188b1 100644
--- a/pkg/analyzer_cli/test/reporter_test.dart
+++ b/pkg/analyzer_cli/test/reporter_test.dart
@@ -4,8 +4,6 @@
import 'package:analyzer/dart/analysis/session.dart';
import 'package:analyzer/error/error.dart';
-import 'package:analyzer/file_system/physical_file_system.dart'
- show PhysicalResourceProvider;
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/analysis/results.dart';
import 'package:analyzer_cli/src/ansi.dart' as ansi;
@@ -111,7 +109,7 @@
return ErrorsResultImpl(
session: _MockAnalysisSession(),
- file: PhysicalResourceProvider.INSTANCE.getFile(path),
+ path: source.fullName,
uri: Uri.file('/'),
lineInfo: lineInfo,
isAugmentation: false,