Unverified Commit 34ba6473 authored by Jenn Magder's avatar Jenn Magder Committed by GitHub

Clean up null assumptions in devfs to prep for null safety migration (#88934)

parent 4dba7d83
......@@ -37,8 +37,8 @@ const String kFontManifestJson = 'FontManifest.json';
const List<Map<String, Object>> kMaterialFonts = <Map<String, Object>>[
<String, Object>{
'family': 'MaterialIcons',
'fonts': <Map<String, Object>>[
<String, Object>{
'fonts': <Map<String, String>>[
<String, String>{
'asset': 'fonts/MaterialIcons-Regular.otf',
},
],
......@@ -161,7 +161,8 @@ class ManifestAssetBundle implements AssetBundle {
@override
bool needsBuild({ String manifestPath = defaultManifestPath }) {
if (_lastBuildTimestamp == null) {
final DateTime lastBuildTimestamp = _lastBuildTimestamp;
if (lastBuildTimestamp == null) {
return true;
}
......@@ -179,13 +180,13 @@ class ManifestAssetBundle implements AssetBundle {
if (dateTime == null) {
continue;
}
if (dateTime.isAfter(_lastBuildTimestamp)) {
if (dateTime.isAfter(lastBuildTimestamp)) {
return true;
}
}
}
return stat.modified.isAfter(_lastBuildTimestamp);
return stat.modified.isAfter(lastBuildTimestamp);
}
@override
......@@ -267,9 +268,7 @@ class ManifestAssetBundle implements AssetBundle {
if (!_splitDeferredAssets || !deferredComponentsEnabled) {
// Include the assets in the regular set of assets if not using deferred
// components.
for (final String componentName in deferredComponentsAssetVariants.keys) {
assetVariants.addAll(deferredComponentsAssetVariants[componentName]);
}
deferredComponentsAssetVariants.values.forEach(assetVariants.addAll);
deferredComponentsAssetVariants.clear();
deferredComponentsEntries.clear();
}
......@@ -457,7 +456,7 @@ class ManifestAssetBundle implements AssetBundle {
return;
}
final DevFSStringContent oldContent = entries[key] as DevFSStringContent;
if (oldContent.string != content.string) {
if (oldContent?.string != content.string) {
entries[key] = content;
}
}
......@@ -479,8 +478,8 @@ class ManifestAssetBundle implements AssetBundle {
// the uncompressed strings to not incur decompression/decoding while making
// the comparison.
if (!entries.containsKey(_kNoticeZippedFile) ||
!(entries[_kNoticeZippedFile] as DevFSStringCompressingBytesContent)
.equals(combinedLicenses)) {
(entries[_kNoticeZippedFile] as DevFSStringCompressingBytesContent)
?.equals(combinedLicenses) != true) {
entries[_kNoticeZippedFile] = DevFSStringCompressingBytesContent(
combinedLicenses,
// A zlib dictionary is a hinting string sequence with the most
......@@ -494,8 +493,16 @@ class ManifestAssetBundle implements AssetBundle {
List<_Asset> _getMaterialAssets() {
final List<_Asset> result = <_Asset>[];
for (final Map<String, Object> family in kMaterialFonts) {
for (final Map<String, Object> font in family['fonts'] as List<Map<String, Object>>) {
final Uri entryUri = _fileSystem.path.toUri(font['asset'] as String);
final Object fonts = family['fonts'];
if (fonts == null) {
continue;
}
for (final Map<String, Object> font in fonts as List<Map<String, String>>) {
final String asset = font['asset'] as String;
if (asset == null) {
continue;
}
final Uri entryUri = _fileSystem.path.toUri(asset);
result.add(_Asset(
baseDir: _fileSystem.path.join(Cache.flutterRoot, 'bin', 'cache', 'artifacts', 'material_fonts'),
relativeUri: Uri(path: entryUri.pathSegments.last),
......@@ -577,22 +584,21 @@ class ManifestAssetBundle implements AssetBundle {
Map<String, Map<_Asset, List<_Asset>>> deferredComponentsAssetVariants
) {
final Map<String, List<String>> jsonObject = <String, List<String>>{};
final List<_Asset> assets = assetVariants.keys.toList();
final Map<_Asset, List<String>> jsonEntries = <_Asset, List<String>>{};
for (final _Asset main in assets) {
assetVariants.forEach((_Asset main, List<_Asset> variants) {
jsonEntries[main] = <String>[
for (final _Asset variant in assetVariants[main])
for (final _Asset variant in variants)
variant.entryUri.path,
];
}
});
if (deferredComponentsAssetVariants != null) {
for (final Map<_Asset, List<_Asset>> componentAssets in deferredComponentsAssetVariants.values) {
for (final _Asset main in componentAssets.keys) {
componentAssets.forEach((_Asset main, List<_Asset> variants) {
jsonEntries[main] = <String>[
for (final _Asset variant in componentAssets[main])
for (final _Asset variant in variants)
variant.entryUri.path,
];
}
});
}
}
final List<_Asset> sortedKeys = jsonEntries.keys.toList()
......@@ -617,7 +623,7 @@ class ManifestAssetBundle implements AssetBundle {
final Uri assetUri = fontAsset.assetUri;
if (assetUri.pathSegments.first == 'packages' &&
!_fileSystem.isFileSync(_fileSystem.path.fromUri(
packageConfig[packageName].packageUriRoot.resolve('../${assetUri.path}')))) {
packageConfig[packageName]?.packageUriRoot?.resolve('../${assetUri.path}')))) {
packageFontAssets.add(FontAsset(
fontAsset.assetUri,
weight: fontAsset.weight,
......@@ -788,16 +794,17 @@ class ManifestAssetBundle implements AssetBundle {
final Uri relativeUri = _fileSystem.path.toUri(relativePath);
final Uri entryUri = asset.symbolicPrefixUri == null
? relativeUri
: asset.symbolicPrefixUri.resolveUri(relativeUri);
variants.add(
_Asset(
baseDir: asset.baseDir,
entryUri: entryUri,
relativeUri: relativeUri,
package: attributedPackage,
),
);
: asset.symbolicPrefixUri?.resolveUri(relativeUri);
if (entryUri != null) {
variants.add(
_Asset(
baseDir: asset.baseDir,
entryUri: entryUri,
relativeUri: relativeUri,
package: attributedPackage,
),
);
}
}
result[asset] = variants;
......@@ -862,9 +869,9 @@ class ManifestAssetBundle implements AssetBundle {
@immutable
class _Asset {
const _Asset({
this.baseDir,
this.relativeUri,
this.entryUri,
@required this.baseDir,
@required this.relativeUri,
@required this.entryUri,
@required this.package,
});
......
......@@ -64,8 +64,9 @@ class DevFSFileContent extends DevFSContent {
FileStat _fileStat;
File _getFile() {
if (_linkTarget != null) {
return _linkTarget;
final File linkTarget = _linkTarget;
if (linkTarget != null) {
return linkTarget;
}
if (file is Link) {
// The link target.
......@@ -75,9 +76,10 @@ class DevFSFileContent extends DevFSContent {
}
void _stat() {
if (_linkTarget != null) {
final File linkTarget = _linkTarget;
if (linkTarget != null) {
// Stat the cached symlink target.
final FileStat fileStat = _linkTarget.statSync();
final FileStat fileStat = linkTarget.statSync();
if (fileStat.type == FileSystemEntityType.notFound) {
_linkTarget = null;
} else {
......@@ -87,7 +89,7 @@ class DevFSFileContent extends DevFSContent {
}
final FileStat fileStat = file.statSync();
_fileStat = fileStat.type == FileSystemEntityType.notFound ? null : fileStat;
if (_fileStat != null && _fileStat.type == FileSystemEntityType.link) {
if (_fileStat != null && _fileStat?.type == FileSystemEntityType.link) {
// Resolve, stat, and maybe cache the symlink target.
final String resolved = file.resolveSymbolicLinksSync();
final File linkTarget = file.fileSystem.file(resolved);
......@@ -96,7 +98,7 @@ class DevFSFileContent extends DevFSContent {
if (fileStat.type == FileSystemEntityType.notFound) {
_fileStat = null;
_linkTarget = null;
} else if (devFSConfig.cacheSymlinks) {
} else if (devFSConfig?.cacheSymlinks == true) {
_linkTarget = linkTarget;
}
}
......@@ -104,25 +106,27 @@ class DevFSFileContent extends DevFSContent {
@override
bool get isModified {
final FileStat _oldFileStat = _fileStat;
final FileStat oldFileStat = _fileStat;
_stat();
if (_oldFileStat == null && _fileStat == null) {
final FileStat newFileStat = _fileStat;
if (oldFileStat == null && newFileStat == null) {
return false;
}
return _oldFileStat == null || _fileStat == null || _fileStat.modified.isAfter(_oldFileStat.modified);
return oldFileStat == null || newFileStat == null || newFileStat.modified.isAfter(oldFileStat.modified);
}
@override
bool isModifiedAfter(DateTime time) {
final FileStat _oldFileStat = _fileStat;
final FileStat oldFileStat = _fileStat;
_stat();
if (_oldFileStat == null && _fileStat == null) {
final FileStat newFileStat = _fileStat;
if (oldFileStat == null && newFileStat == null) {
return false;
}
return time == null
|| _oldFileStat == null
|| _fileStat == null
|| _fileStat.modified.isAfter(time);
|| oldFileStat == null
|| newFileStat == null
|| newFileStat.modified.isAfter(time);
}
@override
......@@ -135,7 +139,7 @@ class DevFSFileContent extends DevFSContent {
}
@override
Future<List<int>> contentsAsBytes() => _getFile().readAsBytes();
Future<List<int>> contentsAsBytes() async => _getFile().readAsBytes();
@override
Stream<List<int>> contentsAsStream() => _getFile().openRead();
......@@ -308,8 +312,8 @@ class _DevFSHttpWriter implements DevFSWriter {
static const int kMaxInFlight = 3;
int _inFlight = 0;
Map<Uri, DevFSContent> _outstanding;
Completer<void> _completer;
Map<Uri, DevFSContent> _outstanding = <Uri, DevFSContent>{};
Completer<void> _completer = Completer<void>();
@override
Future<void> write(Map<Uri, DevFSContent> entries, Uri devFSBase, [DevFSWriter parent]) async {
......@@ -553,8 +557,9 @@ class DevFS {
/// If any other changes were made, or there is an error scanning the file,
/// return `null`.
String _checkIfSingleWidgetReloadApplied() {
if (_widgetCacheOutputFile != null && _widgetCacheOutputFile.existsSync()) {
final String widget = _widgetCacheOutputFile.readAsStringSync().trim();
final File widgetCacheOutputFile = _widgetCacheOutputFile;
if (widgetCacheOutputFile != null && widgetCacheOutputFile.existsSync()) {
final String widget = widgetCacheOutputFile.readAsStringSync().trim();
if (widget.isNotEmpty) {
return widget;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment