Search in sources :

Example 1 with CustomSyntaxTableFileType

use of com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType in project intellij-community by JetBrains.

the class SpellcheckingStrategy method getTokenizer.

@NotNull
public Tokenizer getTokenizer(PsiElement element) {
    if (element instanceof PsiWhiteSpace) {
        return EMPTY_TOKENIZER;
    }
    if (element instanceof PsiLanguageInjectionHost && InjectedLanguageUtil.hasInjections((PsiLanguageInjectionHost) element)) {
        return EMPTY_TOKENIZER;
    }
    if (element instanceof PsiNameIdentifierOwner)
        return new PsiIdentifierOwnerTokenizer();
    if (element instanceof PsiComment) {
        if (SuppressionUtil.isSuppressionComment(element)) {
            return EMPTY_TOKENIZER;
        }
        return myCommentTokenizer;
    }
    if (element instanceof XmlAttributeValue)
        return myXmlAttributeTokenizer;
    if (element instanceof PsiPlainText) {
        PsiFile file = element.getContainingFile();
        FileType fileType = file == null ? null : file.getFileType();
        if (fileType instanceof CustomSyntaxTableFileType) {
            return new CustomFileTypeTokenizer(((CustomSyntaxTableFileType) fileType).getSyntaxTable());
        }
        return TEXT_TOKENIZER;
    }
    if (element instanceof XmlToken) {
        if (((XmlToken) element).getTokenType() == XmlTokenType.XML_DATA_CHARACTERS) {
            PsiElement injection = InjectedLanguageManager.getInstance(element.getProject()).findInjectedElementAt(element.getContainingFile(), element.getTextOffset());
            if (injection == null) {
                return TEXT_TOKENIZER;
            }
        }
    }
    return EMPTY_TOKENIZER;
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) XmlToken(com.intellij.psi.xml.XmlToken) FileType(com.intellij.openapi.fileTypes.FileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with CustomSyntaxTableFileType

use of com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType in project intellij-community by JetBrains.

the class CommentByBlockCommentHandler method findCommentedRange.

@Nullable
private TextRange findCommentedRange(final Commenter commenter) {
    final CharSequence text = myDocument.getCharsSequence();
    final FileType fileType = myFile.getFileType();
    if (fileType instanceof CustomSyntaxTableFileType) {
        Lexer lexer = new CustomFileTypeLexer(((CustomSyntaxTableFileType) fileType).getSyntaxTable());
        final int caretOffset = myCaret.getOffset();
        int commentStart = CharArrayUtil.lastIndexOf(text, commenter.getBlockCommentPrefix(), caretOffset);
        if (commentStart == -1)
            return null;
        lexer.start(text, commentStart, text.length());
        if (lexer.getTokenType() == CustomHighlighterTokenType.MULTI_LINE_COMMENT && lexer.getTokenEnd() >= caretOffset) {
            return new TextRange(commentStart, lexer.getTokenEnd());
        }
        return null;
    }
    final String prefix;
    final String suffix;
    // Custom uncommenter is able to find commented block inside of selected text
    final String selectedText = myCaret.getSelectedText();
    if ((commenter instanceof CustomUncommenter) && selectedText != null) {
        final TextRange commentedRange = ((CustomUncommenter) commenter).findMaximumCommentedRange(selectedText);
        if (commentedRange == null) {
            return null;
        }
        // Uncommenter returns range relative to text start, so we need to shift it to make abosolute.
        return commentedRange.shiftRight(myCaret.getSelectionStart());
    }
    if (commenter instanceof SelfManagingCommenter) {
        SelfManagingCommenter selfManagingCommenter = (SelfManagingCommenter) commenter;
        prefix = selfManagingCommenter.getBlockCommentPrefix(myCaret.getSelectionStart(), myDocument, mySelfManagedCommenterData);
        suffix = selfManagingCommenter.getBlockCommentSuffix(myCaret.getSelectionEnd(), myDocument, mySelfManagedCommenterData);
    } else {
        prefix = trim(commenter.getBlockCommentPrefix());
        suffix = trim(commenter.getBlockCommentSuffix());
    }
    if (prefix == null || suffix == null)
        return null;
    TextRange commentedRange;
    if (commenter instanceof SelfManagingCommenter) {
        commentedRange = ((SelfManagingCommenter) commenter).getBlockCommentRange(myCaret.getSelectionStart(), myCaret.getSelectionEnd(), myDocument, mySelfManagedCommenterData);
    } else {
        if (!testSelectionForNonComments()) {
            return null;
        }
        commentedRange = getSelectedComments(text, prefix, suffix);
    }
    if (commentedRange == null) {
        PsiElement comment = findCommentAtCaret();
        if (comment != null) {
            String commentText = comment.getText();
            if (commentText.startsWith(prefix) && commentText.endsWith(suffix)) {
                commentedRange = comment.getTextRange();
            }
        }
    }
    return commentedRange;
}
Also used : CustomFileTypeLexer(com.intellij.ide.highlighter.custom.CustomFileTypeLexer) Lexer(com.intellij.lexer.Lexer) CustomFileTypeLexer(com.intellij.ide.highlighter.custom.CustomFileTypeLexer) FileType(com.intellij.openapi.fileTypes.FileType) AbstractFileType(com.intellij.openapi.fileTypes.impl.AbstractFileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) CustomUncommenter(com.intellij.lang.CustomUncommenter) TextRange(com.intellij.openapi.util.TextRange) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with CustomSyntaxTableFileType

use of com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType in project intellij-community by JetBrains.

the class CustomFileTypeFoldingBuilder method buildLanguageFoldRegions.

@Override
protected void buildLanguageFoldRegions(@NotNull List<FoldingDescriptor> descriptors, @NotNull PsiElement root, @NotNull Document document, boolean quick) {
    FileType fileType = root.getContainingFile().getFileType();
    if (!(fileType instanceof CustomSyntaxTableFileType)) {
        return;
    }
    CustomFileHighlighter highlighter = new CustomFileHighlighter(((CustomSyntaxTableFileType) fileType).getSyntaxTable());
    buildBraceMatcherBasedFolding(descriptors, root, document, highlighter);
}
Also used : FileType(com.intellij.openapi.fileTypes.FileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) CustomFileHighlighter(com.intellij.ide.highlighter.custom.CustomFileHighlighter) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)

Example 4 with CustomSyntaxTableFileType

use of com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType in project intellij-community by JetBrains.

the class PlatformIdTableBuilding method getTodoIndexer.

@Nullable
public static DataIndexer<TodoIndexEntry, Integer, FileContent> getTodoIndexer(FileType fileType, final VirtualFile virtualFile) {
    final DataIndexer<TodoIndexEntry, Integer, FileContent> extIndexer;
    if (fileType instanceof SubstitutedFileType && !((SubstitutedFileType) fileType).isSameFileType()) {
        SubstitutedFileType sft = (SubstitutedFileType) fileType;
        extIndexer = new CompositeTodoIndexer(getTodoIndexer(sft.getOriginalFileType(), virtualFile), getTodoIndexer(sft.getFileType(), virtualFile));
    } else {
        extIndexer = TodoIndexers.INSTANCE.forFileType(fileType);
    }
    if (extIndexer != null) {
        return extIndexer;
    }
    if (fileType instanceof LanguageFileType) {
        final Language lang = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDef = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
        final TokenSet commentTokens = parserDef != null ? parserDef.getCommentTokens() : null;
        if (commentTokens != null) {
            return new TokenSetTodoIndexer(commentTokens, virtualFile);
        }
    }
    if (fileType instanceof CustomSyntaxTableFileType) {
        return new TokenSetTodoIndexer(ABSTRACT_FILE_COMMENT_TOKENS, virtualFile);
    }
    return null;
}
Also used : FileContent(com.intellij.util.indexing.FileContent) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) SubstitutedFileType(com.intellij.util.indexing.SubstitutedFileType) Language(com.intellij.lang.Language) TokenSet(com.intellij.psi.tree.TokenSet) TodoIndexEntry(com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with CustomSyntaxTableFileType

use of com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType in project intellij-community by JetBrains.

the class IndexPatternSearcher method findCommentTokenRanges.

private static void findCommentTokenRanges(final PsiFile file, final CharSequence chars, final TextRange range, final TIntArrayList commentStarts, final TIntArrayList commentEnds) {
    if (file instanceof PsiPlainTextFile) {
        FileType fType = file.getFileType();
        if (fType instanceof CustomSyntaxTableFileType) {
            Lexer lexer = SyntaxHighlighterFactory.getSyntaxHighlighter(fType, file.getProject(), file.getVirtualFile()).getHighlightingLexer();
            findComments(lexer, chars, range, COMMENT_TOKENS, commentStarts, commentEnds, null);
        } else {
            commentStarts.add(0);
            commentEnds.add(file.getTextLength());
        }
    } else {
        final FileViewProvider viewProvider = file.getViewProvider();
        final Set<Language> relevantLanguages = viewProvider.getLanguages();
        for (Language lang : relevantLanguages) {
            final TIntArrayList commentStartsList = new TIntArrayList();
            final TIntArrayList commentEndsList = new TIntArrayList();
            final SyntaxHighlighter syntaxHighlighter = SyntaxHighlighterFactory.getSyntaxHighlighter(lang, file.getProject(), file.getVirtualFile());
            Lexer lexer = syntaxHighlighter.getHighlightingLexer();
            TokenSet commentTokens = null;
            IndexPatternBuilder builderForFile = null;
            for (IndexPatternBuilder builder : Extensions.getExtensions(IndexPatternBuilder.EP_NAME)) {
                Lexer lexerFromBuilder = builder.getIndexingLexer(file);
                if (lexerFromBuilder != null) {
                    lexer = lexerFromBuilder;
                    commentTokens = builder.getCommentTokenSet(file);
                    builderForFile = builder;
                }
            }
            if (builderForFile == null) {
                final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(lang);
                if (parserDefinition != null) {
                    commentTokens = parserDefinition.getCommentTokens();
                }
            }
            if (commentTokens != null) {
                findComments(lexer, chars, range, commentTokens, commentStartsList, commentEndsList, builderForFile);
                mergeCommentLists(commentStarts, commentEnds, commentStartsList, commentEndsList);
            }
        }
    }
}
Also used : Lexer(com.intellij.lexer.Lexer) ParserDefinition(com.intellij.lang.ParserDefinition) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) TokenSet(com.intellij.psi.tree.TokenSet) SyntaxHighlighter(com.intellij.openapi.fileTypes.SyntaxHighlighter) TIntArrayList(gnu.trove.TIntArrayList) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)

Aggregations

CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)7 Language (com.intellij.lang.Language)4 FileType (com.intellij.openapi.fileTypes.FileType)4 Nullable (org.jetbrains.annotations.Nullable)4 ParserDefinition (com.intellij.lang.ParserDefinition)2 Lexer (com.intellij.lexer.Lexer)2 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)2 TokenSet (com.intellij.psi.tree.TokenSet)2 CustomFileHighlighter (com.intellij.ide.highlighter.custom.CustomFileHighlighter)1 CustomFileTypeLexer (com.intellij.ide.highlighter.custom.CustomFileTypeLexer)1 SyntaxTable (com.intellij.ide.highlighter.custom.SyntaxTable)1 Commenter (com.intellij.lang.Commenter)1 CustomUncommenter (com.intellij.lang.CustomUncommenter)1 FindUsagesProvider (com.intellij.lang.findUsages.FindUsagesProvider)1 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)1 AbstractFileType (com.intellij.openapi.fileTypes.impl.AbstractFileType)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiElement (com.intellij.psi.PsiElement)1 TodoIndexEntry (com.intellij.psi.impl.cache.impl.todo.TodoIndexEntry)1 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)1