Skip to content

Commit cc33f44

Browse files
authored
make DevFSContent descendants immutable (#144664)
`DevFSBytesContent` (and it's descendant `DevFSStringContent`) have setters that change the underlying content. These are unused outside of tests, so this PR removes them. Amongst other things, this could help me refactor flutter/flutter#144660 into something that has fewer pitfalls. This is purely a refactoring.
1 parent 2ebd7f0 commit cc33f44

File tree

2 files changed

+6
-37
lines changed

2 files changed

+6
-37
lines changed

packages/flutter_tools/lib/src/devfs.dart

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,12 @@ class DevFSFileContent extends DevFSContent {
153153
class DevFSByteContent extends DevFSContent {
154154
DevFSByteContent(this._bytes);
155155

156-
List<int> _bytes;
157-
156+
final List<int> _bytes;
157+
final DateTime _creationTime = DateTime.now();
158158
bool _isModified = true;
159-
DateTime _modificationTime = DateTime.now();
160159

161160
List<int> get bytes => _bytes;
162161

163-
set bytes(List<int> value) {
164-
_bytes = value;
165-
_isModified = true;
166-
_modificationTime = DateTime.now();
167-
}
168-
169162
/// Return true only once so that the content is written to the device only once.
170163
@override
171164
bool get isModified {
@@ -176,7 +169,7 @@ class DevFSByteContent extends DevFSContent {
176169

177170
@override
178171
bool isModifiedAfter(DateTime time) {
179-
return _modificationTime.isAfter(time);
172+
return _creationTime.isAfter(time);
180173
}
181174

182175
@override
@@ -196,19 +189,9 @@ class DevFSStringContent extends DevFSByteContent {
196189
: _string = string,
197190
super(utf8.encode(string));
198191

199-
String _string;
192+
final String _string;
200193

201194
String get string => _string;
202-
203-
set string(String value) {
204-
_string = value;
205-
super.bytes = utf8.encode(_string);
206-
}
207-
208-
@override
209-
set bytes(List<int> value) {
210-
string = utf8.decode(value);
211-
}
212195
}
213196

214197
/// A string compressing DevFSContent.
@@ -233,7 +216,7 @@ class DevFSStringCompressingBytesContent extends DevFSContent {
233216

234217
final String _string;
235218
final ZLibEncoder _compressor;
236-
final DateTime _modificationTime = DateTime.now();
219+
final DateTime _creationTime = DateTime.now();
237220

238221
bool _isModified = true;
239222

@@ -249,7 +232,7 @@ class DevFSStringCompressingBytesContent extends DevFSContent {
249232

250233
@override
251234
bool isModifiedAfter(DateTime time) {
252-
return _modificationTime.isAfter(time);
235+
return _creationTime.isAfter(time);
253236
}
254237

255238
@override

packages/flutter_tools/test/general.shard/devfs_test.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,6 @@ void main() {
6767
expect(content.bytes, orderedEquals(<int>[4, 5, 6]));
6868
expect(content.isModified, isTrue);
6969
expect(content.isModified, isFalse);
70-
content.bytes = <int>[7, 8, 9, 2];
71-
expect(content.bytes, orderedEquals(<int>[7, 8, 9, 2]));
72-
expect(content.isModified, isTrue);
73-
expect(content.isModified, isFalse);
7470
});
7571

7672
testWithoutContext('DevFSStringContent', () {
@@ -80,16 +76,6 @@ void main() {
8076
expect(content.bytes, orderedEquals(utf8.encode('some string')));
8177
expect(content.isModified, isTrue);
8278
expect(content.isModified, isFalse);
83-
content.string = 'another string';
84-
expect(content.string, 'another string');
85-
expect(content.bytes, orderedEquals(utf8.encode('another string')));
86-
expect(content.isModified, isTrue);
87-
expect(content.isModified, isFalse);
88-
content.bytes = utf8.encode('foo bar');
89-
expect(content.string, 'foo bar');
90-
expect(content.bytes, orderedEquals(utf8.encode('foo bar')));
91-
expect(content.isModified, isTrue);
92-
expect(content.isModified, isFalse);
9379
});
9480

9581
testWithoutContext('DevFSFileContent', () async {

0 commit comments

Comments
 (0)