Prerequisites
Note
Before you start working with language injections, make sure that IntelliLang plugin is enabled.
The plugin is bundled with IntelliJ IDEA and activated by default. If it is not, enable the plugin.
Overview
You can inject other languages into string literals. This can be done within the source code written in most (but not all) of the supported languages (Java, JavaScript, Groovy, Python, Ruby, XML, PHP, and CSS for IntelliJ IDEA Ultimate Edition). The typical examples are HTML fragments injected into JavaScript code, SQL statements in Java or XML, and so on.
When the editor recognizes a string as a language injection:
- Syntax and error highlighting and coding assistance are extended to this string.
- You can open and modify it in a separate tab in the editor,
as if you were working with the source code in the corresponding language.
To open an injection in the editor, use the Edit <Language> Fragment intention action.
To explain the IntelliJ IDEA editor that certain text should be always treated as an embedded source code, you can use:
- The Inject Language intention action, which is applied to a particular string. Note that if you use this method, it’s possible that the string literal will stay marked as a language injection only within a limited period of time. That is, IntelliJ IDEA, at a certain moment, may “forget” that the corresponding literal is a language injection. The period of the injection “persistence” will depend on the language, context and the modifications that you make in other parts of your source code.
- A dedicated @Language annotation in Java source code, for example, @Language("JavaScript") or @Language("HTML").
- The Language Injection page of the Settings dialog box. Using this page, you can tell IntelliJ IDEA that a certain method parameter, text in an XML tag, or XML attribute should always be treated as embedded source code in another language by creating injection configurations.
IntelliJ IDEA distinguishes the project and global states of injection configurations.
- Character strings configured as project injections are treated as source code only within the current project.
- Character strings configured as global injections are treated as source code at the IntelliJ IDEA level, that is, within any IntelliJ IDEA project.
To toggle between the project and global states, use the Move to Project/Make Global toolbar button
on the Language Injection page of the Settings dialog box.

