From 0b2a897b660d91d173d885909efefef147e14a26 Mon Sep 17 00:00:00 2001 From: orangain Date: Sun, 25 Jun 2023 00:58:07 +0900 Subject: [PATCH] Suppress heuristic new line when dot-qualified expression is after annotation --- .../src/test/resources/localTestData/annotatedExpression.kt | 3 +++ ast/src/commonMain/kotlin/ktast/ast/Writer.kt | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 ast-psi/src/test/resources/localTestData/annotatedExpression.kt diff --git a/ast-psi/src/test/resources/localTestData/annotatedExpression.kt b/ast-psi/src/test/resources/localTestData/annotatedExpression.kt new file mode 100644 index 000000000..c2772ca5b --- /dev/null +++ b/ast-psi/src/test/resources/localTestData/annotatedExpression.kt @@ -0,0 +1,3 @@ +package localTestData + +val x = @Suppress("DEPRECATION") y.foo() \ No newline at end of file diff --git a/ast/src/commonMain/kotlin/ktast/ast/Writer.kt b/ast/src/commonMain/kotlin/ktast/ast/Writer.kt index 2e5c94c49..ae4e74716 100644 --- a/ast/src/commonMain/kotlin/ktast/ast/Writer.kt +++ b/ast/src/commonMain/kotlin/ktast/ast/Writer.kt @@ -622,7 +622,7 @@ open class Writer( append("\n") } } - if (parentNode is Node.Expression.AnnotatedExpression && (node is Node.Expression.BinaryExpression || node is Node.Expression.BinaryTypeExpression)) { + if (parentNode is Node.Expression.AnnotatedExpression && ((node is Node.Expression.BinaryExpression && node.operator !is Node.Keyword.Dot) || node is Node.Expression.BinaryTypeExpression)) { // Annotated expression requires newline between annotation and expression when expression is a binary operation. // This is because, without newline, annotated expression of binary expression is ambiguous with binary expression of annotated expression. if (!containsNewlineOrSemicolon(extrasSinceLastNonSymbol)) {