Search in sources :

Example 6 with Language

use of com.intellij.lang.Language in project idea-handlebars by dmarcotte.

the class HbFileType method getAssociatedFileType.

private static LanguageFileType getAssociatedFileType(VirtualFile file, Project project) {
    if (project == null) {
        return null;
    }
    Language language = TemplateDataLanguageMappings.getInstance(project).getMapping(file);
    LanguageFileType associatedFileType = null;
    if (language != null) {
        associatedFileType = language.getAssociatedFileType();
    }
    if (language == null || associatedFileType == null) {
        associatedFileType = HbLanguage.getDefaultTemplateLang();
    }
    return associatedFileType;
}
Also used : Language(com.intellij.lang.Language) HbLanguage(com.dmarcotte.handlebars.HbLanguage)

Example 7 with Language

use of com.intellij.lang.Language in project idea-handlebars by dmarcotte.

the class HbConfigurationPage method resetCommentLanguageCombo.

private void resetCommentLanguageCombo(Language commentLanguage) {
    final DefaultComboBoxModel model = (DefaultComboBoxModel) myCommenterLanguage.getModel();
    final List<Language> languages = TemplateDataLanguageMappings.getTemplateableLanguages();
    // add using the native Handlebars commenter as an option
    languages.add(HbLanguage.INSTANCE);
    Collections.sort(languages, new Comparator<Language>() {

        @Override
        public int compare(final Language o1, final Language o2) {
            return o1.getID().compareTo(o2.getID());
        }
    });
    for (Language language : languages) {
        model.addElement(language);
    }
    myCommenterLanguage.setRenderer(new ListCellRendererWrapper() {

        @Override
        public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
            setText(value == null ? "" : ((Language) value).getDisplayName());
            if (value != null) {
                final FileType type = ((Language) value).getAssociatedFileType();
                if (type != null) {
                    setIcon(type.getIcon());
                }
            }
        }
    });
    myCommenterLanguage.setSelectedItem(commentLanguage);
}
Also used : Language(com.intellij.lang.Language) HbLanguage(com.dmarcotte.handlebars.HbLanguage) FileType(com.intellij.openapi.fileTypes.FileType) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper)

Example 8 with Language

use of com.intellij.lang.Language in project Main by SpartanRefactoring.

the class LeonidasTipper method getPsiTreeFromString.

/**
     * @param name    the name of the tipper
     * @param content the definition file of the tipper
     * @return PsiFile representing the file of the tipper
     */
private PsiJavaFile getPsiTreeFromString(String name, String content) {
    Language language = JavaLanguage.INSTANCE;
    LightVirtualFile virtualFile = new LightVirtualFile(name, language, content);
    SingleRootFileViewProvider.doNotCheckFileSizeLimit(virtualFile);
    final FileViewProviderFactory factory = LanguageFileViewProviders.INSTANCE.forLanguage(language);
    FileViewProvider viewProvider = factory != null ? factory.createFileViewProvider(virtualFile, language, Utils.getPsiManager(Utils.getProject()), true) : null;
    if (viewProvider == null)
        viewProvider = new SingleRootFileViewProvider(Utils.getPsiManager(ProjectManager.getInstance().getDefaultProject()), virtualFile, true);
    language = viewProvider.getBaseLanguage();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(language);
    if (parserDefinition != null) {
        return (PsiJavaFile) viewProvider.getPsi(language);
    }
    return null;
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) Language(com.intellij.lang.Language) JavaLanguage(com.intellij.lang.java.JavaLanguage) LightVirtualFile(com.intellij.testFramework.LightVirtualFile)

Example 9 with Language

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

the class MavenPluginConfigurationLanguageInjector method getLanguagesToInject.

@Override
public void getLanguagesToInject(@NotNull final PsiLanguageInjectionHost host, @NotNull final InjectedLanguagePlaces injectionPlacesRegistrar) {
    if (host.isValid() && host.getContainingFile().getLanguage().is(HTMLLanguage.INSTANCE))
        return;
    if (!(host instanceof XmlText))
        return;
    final XmlText xmlText = (XmlText) host;
    if (!MavenPluginParamInfo.isSimpleText(xmlText))
        return;
    MavenPluginParamInfo.ParamInfoList infoList = MavenPluginParamInfo.getParamInfoList(xmlText);
    for (MavenPluginParamInfo.ParamInfo info : infoList) {
        Language language = info.getLanguage();
        if (language == null) {
            MavenParamLanguageProvider provider = info.getLanguageProvider();
            if (provider != null) {
                language = provider.getLanguage(xmlText, infoList.getDomCfg());
            }
        }
        if (language != null) {
            injectionPlacesRegistrar.addPlace(language, TextRange.from(0, host.getTextLength()), info.getLanguageInjectionPrefix(), info.getLanguageInjectionSuffix());
            return;
        }
    }
}
Also used : Language(com.intellij.lang.Language) HTMLLanguage(com.intellij.lang.html.HTMLLanguage) XmlText(com.intellij.psi.xml.XmlText)

Example 10 with Language

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

the class PyTypingAnnotationInjector method registerCommentInjection.

@NotNull
private static PyInjectionUtil.InjectionResult registerCommentInjection(@NotNull MultiHostRegistrar registrar, @NotNull PsiLanguageInjectionHost host) {
    final String text = host.getText();
    final Matcher m = PyTypingTypeProvider.TYPE_COMMENT_PATTERN.matcher(text);
    if (m.matches()) {
        final String annotationText = m.group(1);
        if (annotationText != null) {
            final int start = m.start(1);
            final int end = m.end(1);
            if (start < end && allowInjectionInComment(host)) {
                Language language = null;
                if ("ignore".equals(annotationText)) {
                    language = null;
                } else if (isFunctionTypeComment(host)) {
                    language = PyFunctionTypeAnnotationDialect.INSTANCE;
                } else if (isTypingAnnotation(annotationText)) {
                    language = PyDocstringLanguageDialect.getInstance();
                }
                if (language != null) {
                    registrar.startInjecting(language);
                    registrar.addPlace("", "", host, TextRange.create(start, end));
                    registrar.doneInjecting();
                    return new PyInjectionUtil.InjectionResult(true, true);
                }
            }
        }
    }
    return PyInjectionUtil.InjectionResult.EMPTY;
}
Also used : Language(com.intellij.lang.Language) Matcher(java.util.regex.Matcher) NotNull(org.jetbrains.annotations.NotNull)

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