Search in sources :

Example 6 with CustomSyntaxTableFileType

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

the class CommentByLineCommentHandler method getBlockSuitableCommenter.

private static Commenter getBlockSuitableCommenter(final PsiFile file, int offset, int endOffset) {
    final Language languageSuitableForCompleteFragment;
    if (offset >= endOffset) {
        // we are on empty line
        PsiElement element = file.findElementAt(offset);
        if (element != null)
            languageSuitableForCompleteFragment = element.getParent().getLanguage();
        else
            languageSuitableForCompleteFragment = null;
    } else {
        languageSuitableForCompleteFragment = PsiUtilBase.reallyEvaluateLanguageInRange(offset, endOffset, file);
    }
    Commenter blockSuitableCommenter = languageSuitableForCompleteFragment == null ? LanguageCommenters.INSTANCE.forLanguage(file.getLanguage()) : null;
    if (blockSuitableCommenter == null && file.getFileType() instanceof CustomSyntaxTableFileType) {
        blockSuitableCommenter = new Commenter() {

            final SyntaxTable mySyntaxTable = ((CustomSyntaxTableFileType) file.getFileType()).getSyntaxTable();

            @Override
            @Nullable
            public String getLineCommentPrefix() {
                return mySyntaxTable.getLineComment();
            }

            @Override
            @Nullable
            public String getBlockCommentPrefix() {
                return mySyntaxTable.getStartComment();
            }

            @Override
            @Nullable
            public String getBlockCommentSuffix() {
                return mySyntaxTable.getEndComment();
            }

            @Override
            public String getCommentedBlockCommentPrefix() {
                return null;
            }

            @Override
            public String getCommentedBlockCommentSuffix() {
                return null;
            }
        };
    }
    return blockSuitableCommenter;
}
Also used : SyntaxTable(com.intellij.ide.highlighter.custom.SyntaxTable) Language(com.intellij.lang.Language) Commenter(com.intellij.lang.Commenter) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)

Example 7 with CustomSyntaxTableFileType

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

the class IdTableBuilding method getFileTypeIndexer.

@Nullable
public static FileTypeIdIndexer getFileTypeIndexer(FileType fileType) {
    final FileTypeIdIndexer idIndexer = ourIdIndexers.get(fileType);
    if (idIndexer != null) {
        return idIndexer;
    }
    final FileTypeIdIndexer extIndexer = IdIndexers.INSTANCE.forFileType(fileType);
    if (extIndexer != null) {
        return extIndexer;
    }
    final WordsScanner customWordsScanner = CacheBuilderRegistry.getInstance().getCacheBuilder(fileType);
    if (customWordsScanner != null) {
        return new WordsScannerFileTypeIdIndexerAdapter(customWordsScanner);
    }
    if (fileType instanceof LanguageFileType) {
        final Language lang = ((LanguageFileType) fileType).getLanguage();
        final FindUsagesProvider findUsagesProvider = LanguageFindUsages.INSTANCE.forLanguage(lang);
        WordsScanner scanner = findUsagesProvider == null ? null : findUsagesProvider.getWordsScanner();
        if (scanner == null) {
            scanner = new SimpleWordsScanner();
        }
        return new WordsScannerFileTypeIdIndexerAdapter(scanner);
    }
    if (fileType instanceof CustomSyntaxTableFileType) {
        return new WordsScannerFileTypeIdIndexerAdapter(createCustomFileTypeScanner(((CustomSyntaxTableFileType) fileType).getSyntaxTable()));
    }
    return null;
}
Also used : FindUsagesProvider(com.intellij.lang.findUsages.FindUsagesProvider) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) Language(com.intellij.lang.Language) CustomSyntaxTableFileType(com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType) Nullable(org.jetbrains.annotations.Nullable)

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