Search in sources :

Example 91 with Language

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

the class OverrideMethodsHandler method invoke.

@Override
public final void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull PsiFile file) {
    if (!EditorModificationUtil.checkModificationAllowed(editor))
        return;
    if (!FileDocumentManager.getInstance().requestWriting(editor.getDocument(), project)) {
        return;
    }
    Language language = PsiUtilCore.getLanguageAtOffset(file, editor.getCaretModel().getOffset());
    final LanguageCodeInsightActionHandler codeInsightActionHandler = CodeInsightActions.OVERRIDE_METHOD.forLanguage(language);
    if (codeInsightActionHandler != null) {
        codeInsightActionHandler.invoke(project, editor, file);
    }
}
Also used : Language(com.intellij.lang.Language) LanguageCodeInsightActionHandler(com.intellij.lang.LanguageCodeInsightActionHandler)

Example 92 with Language

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

the class FoldingPolicy method isCollapseByDefault.

public static boolean isCollapseByDefault(PsiElement element) {
    final Language lang = element.getLanguage();
    final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(lang);
    try {
        return foldingBuilder != null && foldingBuilder.isCollapsedByDefault(element.getNode());
    } catch (IndexNotReadyException e) {
        LOG.error(e);
        return false;
    }
}
Also used : FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) Language(com.intellij.lang.Language) IndexNotReadyException(com.intellij.openapi.project.IndexNotReadyException)

Example 93 with Language

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

the class FoldingUpdate method getFoldingsFor.

private static void getFoldingsFor(@NotNull PsiFile file, @NotNull Document document, @NotNull FoldingMap elementsToFoldMap, boolean quick) {
    final FileViewProvider viewProvider = file.getViewProvider();
    TextRange docRange = TextRange.from(0, document.getTextLength());
    for (final Language language : viewProvider.getLanguages()) {
        final PsiFile psi = viewProvider.getPsi(language);
        final FoldingBuilder foldingBuilder = LanguageFolding.INSTANCE.forLanguage(language);
        if (psi != null && foldingBuilder != null) {
            for (FoldingDescriptor descriptor : LanguageFolding.buildFoldingDescriptors(foldingBuilder, psi, document, quick)) {
                PsiElement psiElement = descriptor.getElement().getPsi();
                if (psiElement == null) {
                    LOG.error("No PSI for folding descriptor " + descriptor);
                    continue;
                }
                if (!docRange.contains(descriptor.getRange())) {
                    diagnoseIncorrectRange(psi, document, language, foldingBuilder, descriptor, psiElement);
                    continue;
                }
                elementsToFoldMap.putValue(psiElement, descriptor);
            }
        }
    }
}
Also used : FoldingDescriptor(com.intellij.lang.folding.FoldingDescriptor) FoldingBuilder(com.intellij.lang.folding.FoldingBuilder) Language(com.intellij.lang.Language) TextRange(com.intellij.openapi.util.TextRange)

Example 94 with Language

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

the class CommentByBlockCommentHandler method findCommenter.

@Nullable
private static Commenter findCommenter(PsiFile file, Editor editor, Caret caret) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof AbstractFileType) {
        return ((AbstractFileType) fileType).getCommenter();
    }
    Language lang = PsiUtilBase.getLanguageInEditor(caret, file.getProject());
    return getCommenter(file, editor, lang, lang);
}
Also used : AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 95 with Language

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

the class EnterInStringLiteralHandler method isInStringLiteral.

private static boolean isInStringLiteral(@NotNull Editor editor, @NotNull DataContext dataContext, int offset) {
    Language language = EnterHandler.getLanguage(dataContext);
    if (offset > 0 && language != null) {
        QuoteHandler quoteHandler = TypedHandler.getLanguageQuoteHandler(language);
        if (quoteHandler == null) {
            FileType fileType = language.getAssociatedFileType();
            quoteHandler = fileType != null ? TypedHandler.getQuoteHandlerForType(fileType) : null;
        }
        if (quoteHandler != null) {
            EditorHighlighter highlighter = ((EditorEx) editor).getHighlighter();
            HighlighterIterator iterator = highlighter.createIterator(offset - 1);
            return StringEscapesTokenTypes.STRING_LITERAL_ESCAPES.contains(iterator.getTokenType()) || quoteHandler.isInsideLiteral(iterator);
        }
    }
    return false;
}
Also used : EditorEx(com.intellij.openapi.editor.ex.EditorEx) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) JavaLikeQuoteHandler(com.intellij.codeInsight.editorActions.JavaLikeQuoteHandler) QuoteHandler(com.intellij.codeInsight.editorActions.QuoteHandler) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) EditorHighlighter(com.intellij.openapi.editor.highlighter.EditorHighlighter)

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