com.intellij.psi.InjectedLanguagePlaces Java Examples

The following examples show how to use com.intellij.psi.InjectedLanguagePlaces. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SQLInjector.java    From dbunit-extractor with MIT License 6 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host,
                                 @NotNull final InjectedLanguagePlaces places) {
    final boolean isSelectQuery = host.getText().trim().toUpperCase().startsWith("SELECT");
    final boolean isDataSetFile = host.getContainingFile().getText().startsWith("<dataset>");
    if (isDataSetFile && isSelectQuery) {
        final Language language = Language.findLanguageByID("SQL");
        if (language != null) {
            try {
                places.addPlace(language, TextRange.from(0, host.getTextLength()), null, null);
            } catch (Throwable e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example #2
Source File: JsInjector.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host,
                                 @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
    if (host instanceof PsiRawBody) {
        FileType jsFileType = FileTypeManager.getInstance().getFileTypeByExtension("js");
        if (jsFileType instanceof LanguageFileType) {
            Language jsLanguage = ((LanguageFileType) jsFileType).getLanguage();
            PsiRawBody macroHost = (PsiRawBody) host;
            TextRange macroTextRange = macroHost.getMacroTextRange();
            injectionPlacesRegistrar.addPlace(jsLanguage, macroTextRange, null, null);
        }
    }
}
 
Example #3
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host,
                                 @NotNull InjectedLanguagePlaces injectedLanguagePlaces) {
    if (MuleConfigUtils.isMuleFile(host.getContainingFile())) {
        if (host instanceof XmlAttributeValue) {
            // Try to inject a language, somewhat abusing the lazy evaluation of predicates :(
            for (Pair<String, String> language : languages) {
                if (tryInjectLanguage(language.getFirst(), language.getSecond(), host, injectedLanguagePlaces)) {
                    break;
                }
            }
        } else if (host instanceof XmlText) {
            final XmlTag tag = ((XmlText) host).getParentTag();
            if (tag != null) {
                final QName tagName = MuleConfigUtils.getQName(tag);
                if (tagName.equals(globalFunctions) || tagName.equals(expressionComponent) || tagName.equals(expressionTransformer)) {
                    final String scriptingName = MelLanguage.MEL_LANGUAGE_ID;
                    injectLanguage(host, injectedLanguagePlaces, scriptingName);
                } else if (tagName.equals(scriptingScript)) {
                    final String engine = tag.getAttributeValue("engine");
                    if (engine != null) {
                        injectLanguage(host, injectedLanguagePlaces, StringUtil.capitalize(engine));
                    }
                } else if (tagName.equals(dwSetPayload) || tagName.equals(dwSetProperty) || tagName.equals(dwSetVariable) || tagName.equals(dwSetSessionVar)) {
                    injectLanguage(host, injectedLanguagePlaces, WEAVE_LANGUAGE_ID);
                }
            }
        }
    }
}
 
Example #4
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void injectLanguage(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectedLanguagePlaces, String scriptingName) {
    final Language requiredLanguage = Language.findLanguageByID(scriptingName);
    if (requiredLanguage != null) {
        final TextRange range = TextRange.from(0, host.getTextRange().getLength());
        injectedLanguagePlaces.addPlace(requiredLanguage, range, null, null);
    }
}
 
Example #5
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private boolean tryInjectLanguage(@NotNull String langPrefix,
                                  @NotNull String languageId,
                                  @NotNull PsiLanguageInjectionHost host,
                                  @NotNull InjectedLanguagePlaces injectedLanguagePlaces) {
    if (isExpectedLocalName(langPrefix, host)) {
        injectLanguage(langPrefix, languageId, host, injectedLanguagePlaces);
        return true;
    }
    return false;
}
 
Example #6
Source File: MuleLanguageInjector.java    From mule-intellij-plugins with Apache License 2.0 5 votes vote down vote up
private void injectLanguage(String langPrefix, @NotNull String languageId,
                            @NotNull PsiLanguageInjectionHost host,
                            @NotNull InjectedLanguagePlaces injectedLanguagePlaces) {
    // Find the required Language
    final Language requiredLanguage = Language.findLanguageByID(languageId);
    if (requiredLanguage == null) {
        return;
    }
    final TextRange textRange = ((XmlAttributeValue) host).getValueTextRange();
    final int length = getLanguagePrefix(langPrefix).length() + 1;
    final TextRange expressionTextRange = TextRange.from(length, textRange.getLength() - length);
    injectedLanguagePlaces.addPlace(requiredLanguage, expressionTextRange, null, null);
}
 
Example #7
Source File: FusionLanguageInjector.java    From intellij-neos with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
    for (BaseInjection injection : Configuration.getInstance().getInjections(FusionLanguageInjectionSupport.SUPPORT_ID)) {
        if (injection.acceptsPsiElement(host)) {
            Language language = InjectedLanguage.findLanguageById(injection.getInjectedLanguageId());
            if (language != null) {
                injectionPlacesRegistrar.addPlace(language, new TextRange(0, host.getTextLength()), "", "");
            }
        }
    }
}
 
Example #8
Source File: JSGraphQLEndpointDocInjector.java    From js-graphql-intellij-plugin with MIT License 5 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
	if(ApplicationManager.getApplication().isUnitTestMode()) {
		// intellij unit test env doesn't properly support language injection in combination with formatter tests, so skip injection in that case
		return;
	}
	if (host instanceof PsiComment && host.getLanguage() == JSGraphQLEndpointLanguage.INSTANCE) {
		injectionPlacesRegistrar.addPlace(JSGraphQLEndpointDocLanguage.INSTANCE, TextRange.create(0, host.getTextLength()), "", "");
	}
}
 
Example #9
Source File: RegexLanguageInjector.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
  if (host instanceof HaxeRegularExpression) {
    final String text = host.getText();
    final TextRange textRange = new TextRange(text.indexOf('/') + 1, text.lastIndexOf('/'));
    injectionPlacesRegistrar.addPlace(RegExpLanguage.INSTANCE, textRange, null, null);
  }
}
 
Example #10
Source File: JavaScriptInjector.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
    if (getXmlFAssetJsContentPattern().accepts(host)) {
        injectionPlacesRegistrar.addPlace(JavascriptLanguage.INSTANCE, new TextRange(0, host.getTextLength()-1), null, null);
    }
}
 
Example #11
Source File: CssInjector.java    From idea-php-typo3-plugin with MIT License 4 votes vote down vote up
@Override
public void getLanguagesToInject(@NotNull PsiLanguageInjectionHost host, @NotNull InjectedLanguagePlaces injectionPlacesRegistrar) {
    if (getXmlFAssetCssContentPattern().accepts(host)) {
        injectionPlacesRegistrar.addPlace(CSSLanguage.INSTANCE, new TextRange(0, host.getTextLength()-1), null, null);
    }
}