From f2e8464b9815818c2d6222b56e017f02ef60fad6 Mon Sep 17 00:00:00 2001 From: Jake Macdonald Date: Thu, 7 Mar 2024 16:58:00 +0000 Subject: [PATCH] add newline after doc comments, add tests for doc comments Bug: https://github.com/dart-lang/sdk/issues/55128 Change-Id: I6897e33ad291093d460e28a0b0f374d6504418e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356260 Auto-Submit: Jake Macdonald Reviewed-by: Konstantin Shcheglov Commit-Queue: Konstantin Shcheglov --- .../lib/src/macros/executor/builder_impls.dart | 2 +- .../test/macros/executor/executor_test.dart | 5 +++++ .../test/macros/executor/simple_macro.dart | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart b/pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart index a0ae0c68934d..2251a9bba4dd 100644 --- a/pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart +++ b/pkg/_fe_analyzer_shared/lib/src/macros/executor/builder_impls.dart @@ -574,7 +574,7 @@ DeclarationCode _buildFunctionAugmentation( assert(initializers == null || declaration is ConstructorDeclaration); return new DeclarationCode.fromParts([ - if (docComments != null) docComments, + if (docComments != null) ...[docComments, '\n'], if (declaration is MethodDeclaration) ' ', 'augment ', if (declaration is ConstructorDeclaration) ...[ diff --git a/pkg/_fe_analyzer_shared/test/macros/executor/executor_test.dart b/pkg/_fe_analyzer_shared/test/macros/executor/executor_test.dart index 148ffceb3a94..0efa5b6017bf 100644 --- a/pkg/_fe_analyzer_shared/test/macros/executor/executor_test.dart +++ b/pkg/_fe_analyzer_shared/test/macros/executor/executor_test.dart @@ -676,6 +676,7 @@ class LibraryInfo { expect( result.libraryAugmentations.single.debugString().toString(), equalsIgnoringWhitespace(''' + // A comment! augment String myFunction() { print('isExternal: false'); print('isGetter: false'); @@ -733,6 +734,7 @@ class LibraryInfo { expect( result.libraryAugmentations.single.debugString().toString(), equalsIgnoringWhitespace(''' + // A comment! augment String get myVariable { print('isExternal: false'); print('isGetter: true'); @@ -754,6 +756,7 @@ class LibraryInfo { expect( result.libraryAugmentations.single.debugString().toString(), equalsIgnoringWhitespace(''' + // A comment! augment void set myVariable(String value, ) { print('isExternal: false'); print('isGetter: false'); @@ -1020,6 +1023,7 @@ final fieldDefinitionMatchers = [ final methodDefinitionMatchers = [ equalsIgnoringWhitespace(''' + // A comment! augment (String, bool? hello, {String world}) myMethod() { print('definingClass: MyClass'); print('isExternal: false'); @@ -1050,6 +1054,7 @@ final methodDefinitionMatchers = [ final mixinMethodDefinitionMatchers = [ equalsIgnoringWhitespace(''' + // A comment! augment (String, bool? hello, {String world}) myMixinMethod() { print('definingClass: MyMixin'); print('isExternal: false'); diff --git a/pkg/_fe_analyzer_shared/test/macros/executor/simple_macro.dart b/pkg/_fe_analyzer_shared/test/macros/executor/simple_macro.dart index c314eec48ce6..b2c50f85b34b 100644 --- a/pkg/_fe_analyzer_shared/test/macros/executor/simple_macro.dart +++ b/pkg/_fe_analyzer_shared/test/macros/executor/simple_macro.dart @@ -323,7 +323,8 @@ class SimpleMacro @override Future buildDefinitionForFunction( FunctionDeclaration function, FunctionDefinitionBuilder builder) async { - builder.augment(await _buildFunctionAugmentation(function, builder)); + builder.augment(await _buildFunctionAugmentation(function, builder), + docComments: CommentCode.fromString('// A comment!')); } @override