Can IntelliJ treat a Java text block as syntax such as SQL or XML to assist editing/formatting?

1.2k views Asked by At

Java 15 brings us the new JEP 378: Text Blocks feature. This eases working with multi-line strings.

Can IntelliJ be made to parse the text within that block as some kind of syntax? Is there a way for me to tell IntelliJ that a text block is SQL source code or XML data?

If so, can IntelliJ use its code-editing superpowers to assist with colorizing, editing, and formatting the code nested inside my Java via that text block?

1

There are 1 answers

1
Bas Leijdekkers On BEST ANSWER

Yes, text blocks work the same as regular strings in IntelliJ IDEA regarding this functionality. So you can type Alt+Enter, select Inject language or reference and choose the language you want to inject. And in all cases where languages like regular expressions are injected automatically into regular string, they are also injected into text blocks.

2 code blocks with injected sql and xml