diff --git a/flutter_frontend_server/lib/server.dart b/flutter_frontend_server/lib/server.dart index 0c50557a71ecd..e0e8bf8e4dff6 100644 --- a/flutter_frontend_server/lib/server.dart +++ b/flutter_frontend_server/lib/server.dart @@ -224,6 +224,7 @@ class ToStringVisitor extends RecursiveVisitor { node.enclosingLibrary != null && !node.isStatic && !node.isAbstract && + !node.enclosingClass.isEnum && _isInTargetPackage(node) && !_hasKeepAnnotation(node) ) { diff --git a/flutter_frontend_server/test/fixtures/lib/main.dart b/flutter_frontend_server/test/fixtures/lib/main.dart index bfa11f7d1bc5f..fdd3bb9045c79 100644 --- a/flutter_frontend_server/test/fixtures/lib/main.dart +++ b/flutter_frontend_server/test/fixtures/lib/main.dart @@ -9,6 +9,7 @@ void main() { final Paint paint = Paint()..color = Color(0xFFFFFFFF); print(jsonEncode({ 'Paint.toString': paint.toString(), + 'Brightness.toString': Brightness.dark.toString(), 'Foo.toString': Foo().toString(), 'Keep.toString': Keep().toString(), })); diff --git a/flutter_frontend_server/test/to_string_test.dart b/flutter_frontend_server/test/to_string_test.dart index ac70b23697ad3..3ee7570973a67 100644 --- a/flutter_frontend_server/test/to_string_test.dart +++ b/flutter_frontend_server/test/to_string_test.dart @@ -121,6 +121,25 @@ void main(List 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 []); + 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(); @@ -254,6 +273,7 @@ void main(List 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"}', ); @@ -275,6 +295,7 @@ void main(List 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"}', );