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:
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.
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:
Subsequent, give your Language Injection a reputation and specify the language as SQL (or MySQL in my case):
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:
Your dialog ought to appear to be this:
Lastly, restart the IDE.
Now, the following time you employ the prepareStatement technique, your SQL shall be handled as a 1st class language:
For those who can’t coax IntelliJ to determine the language based mostly on context, use an annotation, like this: