IntelliJ has the flexibility to deal with a String literal as a language (SQL or RegEx, for instance). After which, inside that String, IntelliJ will present syntax coloring and auto-completion for the language specified.
Here’s what it appears like in motion:
![](https://miro.medium.com/max/300/1*_vacBkj1JbNlaJngRaP8qQ.png 300w)
JetBrains calls this Language Injection.
All it’s a must to do is inform IntelliJ what language you are attempting to sort in your string literal.
There are a variety methods, however listed here are my 2 favorites:
The prepareStatement technique (from java.sql.Connection) takes 1 argument of sort String. However extra particularly, one argument of sort SQL String. And that argument won’t ever be something apart from SQL. So, we are able to inform IntelliJ that.
Steps
Navigate to Preferences | Editor | Language Injections
Click on on the + button on prime, so as to add a brand new rule and select Generic Kotlin:
![](https://miro.medium.com/max/300/1*h0eTetJ7c8Goq3Lsj0IWRQ.png 300w)
Subsequent, give your Language Injection a reputation and specify the language as SQL (or MySQL in my case):
![](https://miro.medium.com/max/300/1*MnQTx13aAGySU4vG75kDDw.png 300w)
Subsequent, present a Place Sample, so IntelliJ is aware of which string literals are presupposed to be handled as SQL. Right here is our Place Sample:
+ kotlinParameter().
ofFunction(0,kotlinFunction().
withName("prepareStatement").
withReceiver("java.sql.Connection"))
Your dialog ought to appear to be this:
![](https://miro.medium.com/max/300/1*PqL5ND5t0SFEgd_vNkWR7A.png 300w)
Lastly, restart the IDE.
Now, the following time you employ the prepareStatement technique, your SQL shall be handled as a 1st class language:
![](https://miro.medium.com/max/300/1*_vacBkj1JbNlaJngRaP8qQ.png 300w)
For those who can’t coax IntelliJ to determine the language based mostly on context, use an annotation, like this:
![](https://miro.medium.com/max/300/1*StgvRuASaKQb2vhihC6pAw.png 300w)