This feature is supported in the Ultimate edition only.
For language injections in SQL, IntelliJ IDEA provides the following additional features (for general info, see Using Language Injections):
- Auto-injection for XML and JSON data types, see Using auto-injection for XML and JSON.
- Data type patterns, see Using pattern-based injections for user-defined data types.
Using auto-injection for XML and JSON
For values defined as XML and JSON types, the corresponding languages are injected automatically.
Example
- Create an SQL file and open it in the editor.
- Specify PostgreSQL as an SQL dialect for that file.
-
Copy the following into your SQL file:
CREATE TABLE test ( my_xml XML DEFAULT '' );
- Place the cursor between the quotation marks.
- Check the light bulb menu (Alt+Enter): there is the Edit XML Fragment command there which means that XML has been auto-injected.
Using pattern-based injections for user-defined data types
You can create patterns - e.g. for user-defined data types - and associate those patterns with languages. As a result, IntelliJ IDEA, when it comes across a data type that matches the pattern, will inject the language specified for that pattern.
In the following example, we'll create a pattern for a data type ending in DATA and
associate that pattern with XML.
Example
-
In your SQL file, replace
XMLwithMYDATA. - Place the cursor between the quotation marks.
-
Press Alt+Enter.
Note that there is no more Edit XML Fragment command in the menu.
Select Inject by Type, and then select XML (XML files).
-
In the dialog that opens, in the Type pattern field,
specify
(?i).*DATA. (The type patterns are specified using regular expressions. In this example,(?i)turns the case-insensitive mode on;.*stands for any number of any characters.) -
Check the light bulb menu again (Alt+Enter).
The Edit XML Fragment command has become available which means that
XML has been injected for the value of the
MYDATAtype. - To remove the pattern you have just created (if you don't need it), open the Settings / Preferences dialog (e.g. Ctrl+Alt+S), go to the page, find and delete the pattern.