Search in sources :

Example 1 with ReferenceInjector

use of com.intellij.psi.injection.ReferenceInjector in project intellij-community by JetBrains.

the class InjectorUtils method getLanguageByString.

@Nullable
public static Language getLanguageByString(String languageId) {
    Language language = InjectedLanguage.findLanguageById(languageId);
    if (language != null)
        return language;
    ReferenceInjector injector = ReferenceInjector.findById(languageId);
    if (injector != null)
        return injector.toLanguage();
    FileType fileType = FileTypeManager.getInstance().getFileTypeByExtension(languageId);
    return fileType instanceof LanguageFileType ? ((LanguageFileType) fileType).getLanguage() : null;
}
Also used : ReferenceInjector(com.intellij.psi.injection.ReferenceInjector) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with ReferenceInjector

use of com.intellij.psi.injection.ReferenceInjector in project intellij-community by JetBrains.

the class MultiHostRegistrarImpl method startInjecting.

@Override
@NotNull
public MultiHostRegistrar startInjecting(@NotNull Language language) {
    escapers = new SmartList<>();
    shreds = new SmartList<>();
    outChars = new StringBuilder();
    if (!cleared) {
        clear();
        throw new IllegalStateException("Seems you haven't called doneInjecting()");
    }
    if (LanguageParserDefinitions.INSTANCE.forLanguage(language) == null) {
        ReferenceInjector injector = ReferenceInjector.findById(language.getID());
        if (injector == null) {
            throw new UnsupportedOperationException("Cannot inject language '" + language + "' since its getParserDefinition() returns null");
        }
        myLanguage = null;
        myReferenceInjector = injector;
    }
    myLanguage = language;
    //fileExtension = fileType == null ? null : fileType.getDefaultExtension();
    return this;
}
Also used : ReferenceInjector(com.intellij.psi.injection.ReferenceInjector) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ReferenceInjector (com.intellij.psi.injection.ReferenceInjector)2 Language (com.intellij.lang.Language)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1