Search in sources :

Example 16 with ParserDefinition

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

the class StubUpdatingIndex method canHaveStub.

public static boolean canHaveStub(@NotNull VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        final Language l = ((LanguageFileType) fileType).getLanguage();
        final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null) {
            return false;
        }
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        if (elementType instanceof IStubFileElementType) {
            if (((IStubFileElementType) elementType).shouldBuildStubFor(file)) {
                return true;
            }
            FileBasedIndex fileBasedIndex = FileBasedIndex.getInstance();
            if (file instanceof NewVirtualFile && fileBasedIndex instanceof FileBasedIndexImpl && ((FileBasedIndexImpl) fileBasedIndex).getIndex(INDEX_ID).isIndexedStateForFile(((NewVirtualFile) file).getId(), file)) {
                return true;
            }
        }
    }
    final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    return builder != null && builder.acceptsFile(file);
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) NewVirtualFile(com.intellij.openapi.vfs.newvfs.NewVirtualFile)

Example 17 with ParserDefinition

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

the class StubVersionMap method getVersionOwner.

private static Object getVersionOwner(FileType fileType) {
    Object owner = null;
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition != null) {
            final IFileElementType type = parserDefinition.getFileNodeType();
            if (type instanceof IStubFileElementType) {
                owner = type;
            }
        }
    }
    BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
    if (builder != null) {
        owner = builder;
    }
    return owner;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language)

Example 18 with ParserDefinition

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

the class CoreStubTreeLoader method canHaveStub.

@Override
public boolean canHaveStub(VirtualFile file) {
    final FileType fileType = file.getFileType();
    if (fileType instanceof LanguageFileType) {
        Language l = ((LanguageFileType) fileType).getLanguage();
        ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(l);
        if (parserDefinition == null)
            return false;
        final IFileElementType elementType = parserDefinition.getFileNodeType();
        return elementType instanceof IStubFileElementType && ((IStubFileElementType) elementType).shouldBuildStubFor(file);
    } else if (fileType.isBinary()) {
        final BinaryFileStubBuilder builder = BinaryFileStubBuilders.INSTANCE.forFileType(fileType);
        return builder != null && builder.acceptsFile(file);
    }
    return false;
}
Also used : IFileElementType(com.intellij.psi.tree.IFileElementType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType) ParserDefinition(com.intellij.lang.ParserDefinition) IStubFileElementType(com.intellij.psi.tree.IStubFileElementType) Language(com.intellij.lang.Language) FileType(com.intellij.openapi.fileTypes.FileType) LanguageFileType(com.intellij.openapi.fileTypes.LanguageFileType)

Example 19 with ParserDefinition

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

the class ConvertToEntityFix method invoke.

public void invoke(@NotNull Project project, Editor editor, PsiFile file) throws IncorrectOperationException {
    final XmlAttribute attribute = PsiTreeUtil.getContextOfType(myToken.getContainingFile(), XmlAttribute.class, true);
    assert attribute != null;
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(myToken.getLanguage());
    assert parserDefinition != null;
    final PsiFile f = XPathChangeUtil.createXPathFile(myToken, "1 " + myValue + " 2");
    final PsiElement firstChild = f.getFirstChild();
    assert firstChild != null;
    //
    final XPathToken child = PsiTreeUtil.getChildOfType(firstChild, XPathToken.class);
    assert child != null;
    myToken.replace(child);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) ParserDefinition(com.intellij.lang.ParserDefinition) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) XPathToken(org.intellij.lang.xpath.psi.XPathToken)

Example 20 with ParserDefinition

use of com.intellij.lang.ParserDefinition 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

ParserDefinition (com.intellij.lang.ParserDefinition)23 Language (com.intellij.lang.Language)8 ASTNode (com.intellij.lang.ASTNode)7 TokenSet (com.intellij.psi.tree.TokenSet)6 PsiElement (com.intellij.psi.PsiElement)5 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)4 FileType (com.intellij.openapi.fileTypes.FileType)3 PsiFileImpl (com.intellij.psi.impl.source.PsiFileImpl)3 IElementType (com.intellij.psi.tree.IElementType)3 IFileElementType (com.intellij.psi.tree.IFileElementType)3 IStubFileElementType (com.intellij.psi.tree.IStubFileElementType)3 Annotation (com.intellij.lang.annotation.Annotation)2 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 GroovyPsiElement (org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement)2 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)2 GrMethodCallExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression)2 LookupElement (com.intellij.codeInsight.lookup.LookupElement)1 DocumentWindowImpl (com.intellij.injected.editor.DocumentWindowImpl)1 VirtualFileWindowImpl (com.intellij.injected.editor.VirtualFileWindowImpl)1 PsiBuilder (com.intellij.lang.PsiBuilder)1