Quincy Bowers
Quincy Bowers

Reputation: 420

How are Kotlin multiline strings handled in annotations?

I am using Intellij to write a Kotlin repository using JPA. I converted an existing Java class which had a particularly long @Query string.

@Query("SELECT a.column1, a.column2, b.column3, b.column4, b.column5, b.column6) FROM TableA as a JOIN TableB as b ON a.id = b.foreignKeyId WHERE a.column1 = :column1 AND b.column2 = :column2 AND b.column3 IN :column3Values")

public List someFancyMethodName(...);

After converting to Kotlin I turned the annotation parameter into a multiline string and started inserting newlines. Intellij, (helpfully?), inserted pipes for handling the margin.

It ended up looking like this.

@Query("""SELECT a.column1, a.column2, b.column3, b.column4, b.column5, b.column6)
    | FROM TableA as a
    | JOIN TableB as b ON a.id = b.foreignKeyId
    | WHERE a.column1 = :column1
    | AND b.column2 = :column2
    | AND b.column3 IN :column3Values""")
fun someFancyMethodName(...): List<SomeFancyReturnValue>

My first thought is that this is not going to work with the embedded pipes and that Intellij shouldn't be inserting them in an annotation parameter. Or is it smart enough to remove the pipes a on compile when the multiline string is an annotation parameter?

Upvotes: 4

Views: 1406

Answers (1)

yole
yole

Reputation: 97148

This behavior is a bug in the Kotlin plugin; the compiler actually isn't smart enough to remove the | characters. I've filed an issue.

Upvotes: 2

Related Questions