Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
Treat this and super expressions the same way as reference expression…
Browse files Browse the repository at this point in the history
…s for formatting dot-qualified expressions
  • Loading branch information
hovinen committed Mar 25, 2021
1 parent ed98cd9 commit b1f8052
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ internal class DotQualifiedExpressionScanner(private val kotlinScanner: KotlinSc
}

private fun NodePatternBuilder.methodCallOnReferenceExpression() {
nodeOfType(KtNodeTypes.REFERENCE_EXPRESSION) thenMapToTokens { nodes ->
kotlinScanner.scanNodes(nodes, ScannerState.STATEMENT)
}
nodeOfOneOfTypes(
KtNodeTypes.REFERENCE_EXPRESSION,
KtNodeTypes.THIS_EXPRESSION,
KtNodeTypes.SUPER_EXPRESSION
) thenMapToTokens { nodes -> kotlinScanner.scanNodes(nodes, ScannerState.STATEMENT) }
possibleWhitespace()
dotToken() thenMapToTokens { nodes ->
listOf(emptyBreakPoint(), LeafNodeToken(nodes.first().text))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3357,6 +3357,33 @@ class KotlinFormatterTest {
)
}

@ParameterizedTest
@ValueSource(strings = ["this", "super"])
fun `does not break on a single dot expression with keyword`(reference: String) {
val result =
KotlinFormatter(maxLineLength = 50)
.format(
"""
fun myFunction() {
$reference.aMethod(aParameter, anotherParameter, aThirdParameter)
}
""".trimIndent()
)

assertThat(result)
.isEqualTo(
"""
fun myFunction() {
$reference.aMethod(
aParameter,
anotherParameter,
aThirdParameter
)
}
""".trimIndent()
)
}

@Test
fun `breaks at first dot operator in dot expression when necessary`() {
val result =
Expand Down

0 comments on commit b1f8052

Please sign in to comment.