Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions flutter_frontend_server/lib/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class ToStringVisitor extends RecursiveVisitor<void> {
node.enclosingLibrary != null &&
!node.isStatic &&
!node.isAbstract &&
!node.enclosingClass.isEnum &&
_isInTargetPackage(node) &&
!_hasKeepAnnotation(node)
) {
Expand Down
1 change: 1 addition & 0 deletions flutter_frontend_server/test/fixtures/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void main() {
final Paint paint = Paint()..color = Color(0xFFFFFFFF);
print(jsonEncode(<String, String>{
'Paint.toString': paint.toString(),
'Brightness.toString': Brightness.dark.toString(),
'Foo.toString': Foo().toString(),
'Keep.toString': Keep().toString(),
}));
Expand Down
21 changes: 21 additions & 0 deletions flutter_frontend_server/test/to_string_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,25 @@ void main(List<String> args) async {
verifyNever(statement.replaceWith(any));
});

test('ToStringVisitor ignores enum toString', () {
final ToStringVisitor visitor = ToStringVisitor(uiAndFlutter);
final MockProcedure procedure = MockProcedure();
final MockFunctionNode function = MockFunctionNode();
final MockStatement statement = MockStatement();
final Library library = Library(Uri.parse('package:some_package/src/blah.dart'));
when(procedure.function).thenReturn(function);
when(procedure.name).thenReturn(Name('toString'));
when(procedure.annotations).thenReturn(const <Expression>[]);
when(procedure.enclosingLibrary).thenReturn(library);
when(procedure.enclosingClass).thenReturn(Class()..isEnum = true);
when(procedure.isAbstract).thenReturn(false);
when(procedure.isStatic).thenReturn(false);
when(function.body).thenReturn(statement);

visitor.visitProcedure(procedure);
verifyNever(statement.replaceWith(any));
});

test('ToStringVisitor ignores non-specified libraries', () {
final ToStringVisitor visitor = ToStringVisitor(uiAndFlutter);
final MockProcedure procedure = MockProcedure();
Expand Down Expand Up @@ -254,6 +273,7 @@ void main(List<String> args) async {
expect(
runResult.stdout.trim(),
'{"Paint.toString":"Paint(Color(0xffffffff))",'
'"Brightness.toString":"Brightness.dark",'
'"Foo.toString":"I am a Foo",'
'"Keep.toString":"I am a Keep"}',
);
Expand All @@ -275,6 +295,7 @@ void main(List<String> args) async {
expect(
runResult.stdout.trim(),
'{"Paint.toString":"Instance of \'Paint\'",'
'"Brightness.toString":"Brightness.dark",'
'"Foo.toString":"Instance of \'Foo\'",'
'"Keep.toString":"I am a Keep"}',
);
Expand Down