Search in sources :

Example 46 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class ConcatenationInjector method getLanguagesToInject.

public void getLanguagesToInject(@NotNull final MultiHostRegistrar registrar, @NotNull PsiElement... operands) {
    if (operands.length == 0)
        return;
    boolean hasLiteral = false;
    InjectedLanguage tempInjectedLanguage = null;
    PsiFile containingFile = null;
    for (PsiElement operand : operands) {
        if (PsiUtilEx.isStringOrCharacterLiteral(operand)) {
            hasLiteral = true;
            if (containingFile == null) {
                containingFile = operands[0].getContainingFile();
            }
            tempInjectedLanguage = myTemporaryPlacesRegistry.getLanguageFor((PsiLanguageInjectionHost) operand, containingFile);
            if (tempInjectedLanguage != null)
                break;
        }
    }
    if (!hasLiteral)
        return;
    final Language tempLanguage = tempInjectedLanguage == null ? null : tempInjectedLanguage.getLanguage();
    final PsiFile finalContainingFile = containingFile;
    InjectionProcessor injectionProcessor = new InjectionProcessor(myConfiguration, mySupport, operands) {

        @Override
        protected void processInjection(Language language, List<Trinity<PsiLanguageInjectionHost, InjectedLanguage, TextRange>> list, boolean settingsAvailable, boolean unparsable) {
            InjectorUtils.registerInjection(language, list, finalContainingFile, registrar);
            InjectorUtils.registerSupport(mySupport, settingsAvailable, registrar);
            InjectorUtils.putInjectedFileUserData(registrar, InjectedLanguageUtil.FRANKENSTEIN_INJECTION, unparsable ? Boolean.TRUE : null);
        }

        @Override
        protected boolean areThereInjectionsWithName(String methodName, boolean annoOnly) {
            if (methodName == null)
                return false;
            if (getAnnotatedElementsValue().contains(methodName)) {
                return true;
            }
            if (!annoOnly && getXmlAnnotatedElementsValue().contains(methodName)) {
                return true;
            }
            return false;
        }
    };
    if (tempLanguage != null) {
        BaseInjection baseInjection = new BaseInjection(JavaLanguageInjectionSupport.JAVA_SUPPORT_ID);
        baseInjection.setInjectedLanguageId(tempInjectedLanguage.getID());
        injectionProcessor.processInjectionInner(baseInjection, false);
        InjectorUtils.putInjectedFileUserData(registrar, LanguageInjectionSupport.TEMPORARY_INJECTED_LANGUAGE, tempInjectedLanguage);
    } else {
        injectionProcessor.processInjections();
    }
}
Also used : InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) Language(com.intellij.lang.Language) InjectedLanguage(org.intellij.plugins.intelliLang.inject.InjectedLanguage) TextRange(com.intellij.openapi.util.TextRange) BaseInjection(org.intellij.plugins.intelliLang.inject.config.BaseInjection)

Example 47 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class XDebuggerEditorBase method createLanguagePopup.

private ListPopup createLanguagePopup() {
    DefaultActionGroup actions = new DefaultActionGroup();
    for (Language language : getSupportedLanguages()) {
        //noinspection ConstantConditions
        actions.add(new AnAction(language.getDisplayName(), null, language.getAssociatedFileType().getIcon()) {

            @Override
            public void actionPerformed(@NotNull AnActionEvent e) {
                XExpression currentExpression = getExpression();
                setExpression(new XExpressionImpl(currentExpression.getExpression(), language, currentExpression.getCustomInfo()));
                requestFocusInEditor();
            }
        });
    }
    DataContext dataContext = DataManager.getInstance().getDataContext(getComponent());
    return JBPopupFactory.getInstance().createActionGroupPopup("Choose Language", actions, dataContext, JBPopupFactory.ActionSelectionAid.SPEEDSEARCH, false);
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) Language(com.intellij.lang.Language) XExpressionImpl(com.intellij.xdebugger.impl.breakpoints.XExpressionImpl) XExpression(com.intellij.xdebugger.XExpression) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 48 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class InjectLanguageAction method getAllInjectables.

public static List<Injectable> getAllInjectables() {
    Language[] languages = InjectedLanguage.getAvailableLanguages();
    List<Injectable> list = new ArrayList<>();
    for (Language language : languages) {
        list.add(Injectable.fromLanguage(language));
    }
    list.addAll(Arrays.asList(ReferenceInjector.EXTENSION_POINT_NAME.getExtensions()));
    Collections.sort(list);
    return list;
}
Also used : Injectable(com.intellij.psi.injection.Injectable) Language(com.intellij.lang.Language) PlainTextLanguage(com.intellij.openapi.fileTypes.PlainTextLanguage) ArrayList(java.util.ArrayList)

Example 49 with Language

use of com.intellij.lang.Language 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 50 with Language

use of com.intellij.lang.Language in project intellij-community by JetBrains.

the class UnInjectLanguageAction method defaultFunctionalityWorked.

private static boolean defaultFunctionalityWorked(final PsiLanguageInjectionHost host) {
    final THashSet<String> languages = new THashSet<>();
    final List<Pair<PsiElement, TextRange>> files = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
    if (files == null)
        return false;
    for (Pair<PsiElement, TextRange> pair : files) {
        for (Language lang = pair.first.getLanguage(); lang != null; lang = lang.getBaseLanguage()) {
            languages.add(lang.getID());
        }
    }
    // todo therefore this part doesn't work for java
    return Configuration.getProjectInstance(host.getProject()).setHostInjectionEnabled(host, languages, false);
}
Also used : Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange) THashSet(gnu.trove.THashSet) Pair(com.intellij.openapi.util.Pair)

Aggregations

Language (com.intellij.lang.Language)292 NotNull (org.jetbrains.annotations.NotNull)58 Nullable (org.jetbrains.annotations.Nullable)49 PsiElement (com.intellij.psi.PsiElement)46 PsiFile (com.intellij.psi.PsiFile)45 FileType (com.intellij.openapi.fileTypes.FileType)31 Project (com.intellij.openapi.project.Project)31 TextRange (com.intellij.openapi.util.TextRange)25 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)23 VirtualFile (com.intellij.openapi.vfs.VirtualFile)21 FileViewProvider (com.intellij.psi.FileViewProvider)21 HbLanguage (com.dmarcotte.handlebars.HbLanguage)20 JavaLanguage (com.intellij.lang.java.JavaLanguage)16 Editor (com.intellij.openapi.editor.Editor)14 XMLLanguage (com.intellij.lang.xml.XMLLanguage)12 TemplateLanguageFileViewProvider (com.intellij.psi.templateLanguages.TemplateLanguageFileViewProvider)11 List (java.util.List)11 HTMLLanguage (com.intellij.lang.html.HTMLLanguage)9 JavascriptLanguage (com.intellij.lang.javascript.JavascriptLanguage)9 Document (com.intellij.openapi.editor.Document)9