Refactor Cider FileState.
The general direction is to make pieces of data that are produced together to be stored together, and so be available together. _FileStateLocation is created before FileState, so it is separated. Any FileState has some unlinked state, so we pass _FileStateUnlinked into the constructor. In Cider we don't refresh files, we discard them and recreate. So, '_unlinked' is a final field. Practically FileState works as a wrapper around _FileStateUnlinked. It could probably have been inlined into FileState. My excuse for not doing this is that in DAS, at least at the moment, we keep FileState instances and refresh them with replacing their unlinked states. So, they should be separate objects. Change-Id: I9439a4021e6efa9e4375eceb5eecf534eabda168 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217860 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Keerti Parthasarathy <keertip@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
9eddeaeb3a
commit
1aa6fa4776
@@ -110,7 +110,7 @@ class LibraryAnalyzer {
|
||||
|
||||
// Parse all files.
|
||||
performance.run('parse', (performance) {
|
||||
for (FileState file in _library.libraryFiles) {
|
||||
for (FileState file in _library.files().ofLibrary) {
|
||||
if (completionPath == null || file.path == completionPath) {
|
||||
units[file] = _parse(
|
||||
file: file,
|
||||
@@ -231,19 +231,19 @@ class LibraryAnalyzer {
|
||||
|
||||
if (_analysisOptions.lint) {
|
||||
performance.run('computeLints', (performance) {
|
||||
var allUnits = _library.libraryFiles.map((file) {
|
||||
var allUnits = _library.files().ofLibrary.map((file) {
|
||||
var content = getFileContent(file);
|
||||
return LinterContextUnit(content, units[file]!);
|
||||
}).toList();
|
||||
for (int i = 0; i < allUnits.length; i++) {
|
||||
_computeLints(_library.libraryFiles[i], allUnits[i], allUnits);
|
||||
_computeLints(_library.files().ofLibrary[i], allUnits[i], allUnits);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// This must happen after all other diagnostics have been computed but
|
||||
// before the list of diagnostics has been filtered.
|
||||
for (var file in _library.libraryFiles) {
|
||||
for (var file in _library.files().ofLibrary) {
|
||||
IgnoreValidator(
|
||||
_getErrorReporter(file),
|
||||
_getErrorListener(file).errors,
|
||||
@@ -472,7 +472,7 @@ class LibraryAnalyzer {
|
||||
}
|
||||
|
||||
bool _isExistingSource(Source source) {
|
||||
for (var file in _library.directReferencedFiles) {
|
||||
for (var file in _library.files().directReferencedFiles) {
|
||||
if (file.uri == source.uri) {
|
||||
return file.exists;
|
||||
}
|
||||
@@ -595,7 +595,7 @@ class LibraryAnalyzer {
|
||||
} else if (directive is PartDirectiveImpl) {
|
||||
StringLiteral partUri = directive.uri;
|
||||
|
||||
FileState partFile = _library.partedFiles[partIndex];
|
||||
FileState partFile = _library.files().parted[partIndex];
|
||||
var partUnit = units[partFile]!;
|
||||
CompilationUnitElement partElement = _libraryElement.parts[partIndex];
|
||||
partUnit.element = partElement;
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -430,7 +430,7 @@ class FileResolver {
|
||||
var libraryFile = file;
|
||||
var partOfLibrary = file.partOfLibrary;
|
||||
if (partOfLibrary != null) {
|
||||
if (partOfLibrary.libraryFiles.contains(file)) {
|
||||
if (partOfLibrary.files().ofLibrary.contains(file)) {
|
||||
libraryFile = partOfLibrary;
|
||||
}
|
||||
}
|
||||
@@ -477,7 +477,7 @@ class FileResolver {
|
||||
var libraryFile = file;
|
||||
var partOfLibrary = file.partOfLibrary;
|
||||
if (partOfLibrary != null) {
|
||||
if (partOfLibrary.libraryFiles.contains(file)) {
|
||||
if (partOfLibrary.files().ofLibrary.contains(file)) {
|
||||
libraryFile = partOfLibrary;
|
||||
}
|
||||
}
|
||||
@@ -509,7 +509,7 @@ class FileResolver {
|
||||
libraryContext!.elementFactory,
|
||||
contextObjects!.inheritanceManager,
|
||||
libraryFile,
|
||||
(file) => file.getContentWithSameDigest(),
|
||||
(file) => file.getContent(),
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -522,7 +522,7 @@ class FileResolver {
|
||||
});
|
||||
} catch (exception, stackTrace) {
|
||||
var fileContentMap = <String, String>{};
|
||||
for (var file in libraryFile.libraryFiles) {
|
||||
for (var file in libraryFile.files().ofLibrary) {
|
||||
var path = file.path;
|
||||
fileContentMap[path] = _getFileContent(path);
|
||||
}
|
||||
@@ -543,7 +543,7 @@ class FileResolver {
|
||||
file.exists,
|
||||
file.getContent(),
|
||||
file.lineInfo,
|
||||
file.unlinked.unit.hasPartOfDirective,
|
||||
file.unlinkedUnit.hasPartOfDirective,
|
||||
fileResult.unit,
|
||||
fileResult.errors,
|
||||
);
|
||||
@@ -822,8 +822,8 @@ class _LibraryContext {
|
||||
|
||||
var unitsInformativeBytes = <Uri, Uint8List>{};
|
||||
for (var library in cycle.libraries) {
|
||||
for (var file in library.libraryFiles) {
|
||||
var informativeBytes = file.unlinked.unit.informativeBytes;
|
||||
for (var file in library.files().ofLibrary) {
|
||||
var informativeBytes = file.unlinkedUnit.informativeBytes;
|
||||
unitsInformativeBytes[file.uri] = informativeBytes;
|
||||
}
|
||||
}
|
||||
@@ -838,10 +838,10 @@ class _LibraryContext {
|
||||
|
||||
var inputUnits = <link2.LinkInputUnit>[];
|
||||
var partIndex = -1;
|
||||
for (var file in libraryFile.libraryFiles) {
|
||||
for (var file in libraryFile.files().ofLibrary) {
|
||||
var isSynthetic = !file.exists;
|
||||
|
||||
var content = file.getContentWithSameDigest();
|
||||
var content = file.getContent();
|
||||
performance.getDataInt('parseCount').increment();
|
||||
performance.getDataInt('parseLength').add(content.length);
|
||||
|
||||
@@ -852,7 +852,7 @@ class _LibraryContext {
|
||||
|
||||
String? partUriStr;
|
||||
if (partIndex >= 0) {
|
||||
partUriStr = libraryFile.unlinked.unit.parts[partIndex];
|
||||
partUriStr = libraryFile.unlinkedUnit.parts[partIndex];
|
||||
}
|
||||
partIndex++;
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ import 'package:analyzer/src/test_utilities/find_element.dart';
|
||||
import 'package:analyzer/src/test_utilities/find_node.dart';
|
||||
import 'package:analyzer/src/test_utilities/mock_sdk.dart';
|
||||
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
|
||||
import 'package:analyzer/src/util/performance/operation_performance.dart';
|
||||
import 'package:analyzer/src/workspace/bazel.dart';
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:linter/src/rules.dart';
|
||||
@@ -71,8 +72,14 @@ class FileResolutionTest with ResourceProviderMixin, ResolutionTest {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<ResolvedUnitResult> resolveFile(String path) async {
|
||||
result = fileResolver.resolve(path: path);
|
||||
Future<ResolvedUnitResult> resolveFile(
|
||||
String path, {
|
||||
OperationPerformanceImpl? performance,
|
||||
}) async {
|
||||
result = fileResolver.resolve(
|
||||
path: path,
|
||||
performance: performance,
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user