Inject code in custom language

Hi every body,

I'm trying to inject java code in my custom language inside String literals. I achieve that, but now:

I don't want to put the complete java class inside the string to avoid that java analyzer throws errors, because the content of the string will be always the body of a method. So I guess cannot use the Injection Language

Also I wish to edit this java code in a quick editor. I saw these threads:, and
Both talks about using QuickEditorAction. So I overrided it and it works, but it uses a virtual file that I supose that is created an managed by the InjectionLanguage feature, so I cannot edit use a quick editor without previous language injection.

Basically what I need is edit the contains of a string in a java virtual file as QuickEditorAction with the features of java editor. I could wrap the string value in a dummy class and method when the virtual file was created to get the context, but when I close the QuickEditor the String only had the method body. An example:


var code updateValue= "animal.setValue(100)"


public class Dummy extends XX {

     public void updateValue() {

I don't need to have synchronized both.

An idea:
I could to create just an editor view creating a dummy virtual file with the dummy wrap and when I close the editor update the value of the string.
How I could do that?

I've tried to explain as well as I could xD.

Any Idea?


Comment actions Permalink

You can use language injection even if the contents of your language fragment is not a complete class. In InjectedLanguagePlaces.addPlace(), pass the necessary prefix and suffix text into the correspondingly named parameters.

Comment actions Permalink

Thanks! It worked well, but I have two questions:
Is there any way to reformat the code when the fragment will be opened using the same action "edit java fragment"?

Is there ant way to force the ide to check the java semantic errors(reference, in a java project) in the fragment code?

Also in case of some reference will no recognized at first try to deduce the Class as is done in a java project and include in the imports.


Comment actions Permalink

Same here.

I’m currently using injection of Java into my custom language too. I’ve already implemented LanguageInjector and added suffix and prefix. This ones work fine.
What I’ve stumbled upon is that IDE doesn’t analyze injectes code.
For example, my prefix is ‘class C { void m() {‘, suffix is ‘}}’ and injected fragment is ‘return “string”; return “string”;
I see no errors about returning String from void method or unreachable code at second return. I can also define private variables and do every other forbidden stuff that will never get compiled.

What must be done in order to enable code analysis of injected fragments?


Please sign in to leave a comment.