Generally I'd use `Language` annotation on a Strin...
# codereview
a
Generally I'd use
Language
annotation on a String literal for syntax highlighting and such, for example
Copy code
@Language("SQL")
val sql = "SELECT weight, name FROM boxes"
But I'm reviewing code where parameters are annotated with it:
Copy code
`fun doSomething(@Language("JSON") payload: String) { ...
why would we want to do that? what does it buy us?
p
language injection at the call-site for literals, i.e.
Copy code
doSomething("""{"this": "would automatically be highlighted as JSON"}""")
1
gratitude thank you 1
And it's probably my PR you're reviewing 😄
a
yes - and TIL. TY for explaining
kotest intensifies 1
k
This annotation only affects IntelliJ IDEA inspections as far as I know. Is there a way to make it fail a Gradle build if you use invalid syntax?
p
Not that I'm aware of, no - you could possibly write an annotation processor that finds and validates them, but you wouldn't be able to validate dynamic strings like
"""{"my-key": "${value}"}"""