Search in sources :

Example 96 with Language

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

the class TabPostFormatProcessor method doProcess.

@NotNull
private static TextRange doProcess(@NotNull PsiElement source, @NotNull TextRange range, @NotNull CodeStyleSettings settings) {
    ASTNode node = source.getNode();
    if (node == null) {
        return range;
    }
    Language language = source.getLanguage();
    if (language != JavaLanguage.INSTANCE) {
        // this logic to other languages as well.
        return range;
    }
    if (!source.isValid())
        return range;
    PsiFile file = source.getContainingFile();
    CommonCodeStyleSettings.IndentOptions indentOptions = settings.getIndentOptionsByFile(file, range);
    boolean useTabs = indentOptions.USE_TAB_CHARACTER;
    boolean smartTabs = indentOptions.SMART_TABS;
    int tabWidth = indentOptions.TAB_SIZE;
    return processViaPsi(node, range, new TreeHelperImpl(), useTabs, smartTabs, tabWidth);
}
Also used : Language(com.intellij.lang.Language) JavaLanguage(com.intellij.lang.java.JavaLanguage) ASTNode(com.intellij.lang.ASTNode) CommonCodeStyleSettings(com.intellij.psi.codeStyle.CommonCodeStyleSettings) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 97 with Language

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

the class InspectionEngine method addDialects.

private static void addDialects(@NotNull List<PsiElement> elements, @NotNull Set<Language> outProcessedLanguages, @NotNull Set<String> outDialectIds) {
    for (PsiElement element : elements) {
        Language language = element.getLanguage();
        outDialectIds.add(language.getID());
        if (outProcessedLanguages.add(language)) {
            for (Language dialect : language.getDialects()) {
                outDialectIds.add(dialect.getID());
            }
        }
    }
}
Also used : Language(com.intellij.lang.Language)

Example 98 with Language

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

the class ExternalAnnotatorBatchInspection method checkFile.

/**
   * To be invoked during batch run
   */
@NotNull
default default ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull GlobalInspectionContext context, @NotNull InspectionManager manager) {
    final String shortName = getShortName();
    final FileViewProvider viewProvider = file.getViewProvider();
    final Set<Language> relevantLanguages = viewProvider.getLanguages();
    for (Language language : relevantLanguages) {
        PsiFile psiRoot = viewProvider.getPsi(language);
        final List<ExternalAnnotator> externalAnnotators = ExternalLanguageAnnotators.allForFile(language, psiRoot);
        for (ExternalAnnotator annotator : externalAnnotators) {
            if (shortName.equals(annotator.getPairedBatchInspectionShortName())) {
                return ExternalAnnotatorInspectionVisitor.checkFileWithExternalAnnotator(file, manager, false, annotator);
            }
        }
    }
    return ProblemDescriptor.EMPTY_ARRAY;
}
Also used : ExternalAnnotator(com.intellij.lang.annotation.ExternalAnnotator) FileViewProvider(com.intellij.psi.FileViewProvider) Language(com.intellij.lang.Language) PsiFile(com.intellij.psi.PsiFile) NotNull(org.jetbrains.annotations.NotNull)

Example 99 with Language

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

the class DiffUtil method createEditorHighlighter.

@Nullable
private static EditorHighlighter createEditorHighlighter(@Nullable Project project, @NotNull DocumentContent content) {
    FileType type = content.getContentType();
    VirtualFile file = content.getHighlightFile();
    Language language = content.getUserData(DiffUserDataKeys.LANGUAGE);
    EditorHighlighterFactory highlighterFactory = EditorHighlighterFactory.getInstance();
    if (language != null) {
        SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(language, project, file);
        return highlighterFactory.createEditorHighlighter(syntaxHighlighter, EditorColorsManager.getInstance().getGlobalScheme());
    }
    if (file != null && file.isValid()) {
        if ((type == null || type == PlainTextFileType.INSTANCE) || file.getFileType() == type || file instanceof LightVirtualFile) {
            return highlighterFactory.createEditorHighlighter(project, file);
        }
    }
    if (type != null) {
        return highlighterFactory.createEditorHighlighter(project, type);
    }
    return null;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) Language(com.intellij.lang.Language) PlainTextFileType(com.intellij.openapi.fileTypes.PlainTextFileType) FileType(com.intellij.openapi.fileTypes.FileType) LightVirtualFile(com.intellij.testFramework.LightVirtualFile) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) EditorHighlighterFactory(com.intellij.openapi.editor.highlighter.EditorHighlighterFactory)

Example 100 with Language

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

the class AutoFormatTypedHandler method isEnabled.

private static boolean isEnabled(Editor editor) {
    boolean isEnabled = myIsEnabledInTests && ApplicationManager.getApplication().isUnitTestMode() || Registry.is("editor.reformat.on.typing");
    if (!isEnabled) {
        return false;
    }
    Project project = editor.getProject();
    Language language = null;
    if (project != null) {
        PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
        if (file != null) {
            language = file.getLanguage();
        }
    }
    return language == JavaLanguage.INSTANCE;
}
Also used : Project(com.intellij.openapi.project.Project) Language(com.intellij.lang.Language) JavaLanguage(com.intellij.lang.java.JavaLanguage) PsiFile(com.intellij.psi.PsiFile)

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