Search in sources :

Example 11 with ParserDefinition

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

the class StructuralSearchProfileBase method isStringLiteral.

protected boolean isStringLiteral(PsiElement element) {
    if (element == null)
        return false;
    final ASTNode astNode = element.getNode();
    if (astNode == null) {
        return false;
    }
    final IElementType elementType = astNode.getElementType();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(element.getLanguage());
    if (parserDefinition != null) {
        final TokenSet literals = parserDefinition.getStringLiteralElements();
        return literals.contains(elementType);
    }
    return false;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ParserDefinition(com.intellij.lang.ParserDefinition) TokenSet(com.intellij.psi.tree.TokenSet) ASTNode(com.intellij.lang.ASTNode)

Example 12 with ParserDefinition

use of com.intellij.lang.ParserDefinition in project android by JetBrains.

the class GradleEditorValueExtractor method visitReferenceExpression.

@Override
public void visitReferenceExpression(GrReferenceExpression expression) {
    if (expression.getParent() instanceof GrMethodCallExpression) {
        // This is a reference expression which points to the method name. We're not interested in it, so, just return.
        return;
    }
    GrExpression qualifier = expression.getQualifierExpression();
    if (qualifier == null) {
        myContext.addCachedVariable(expression.getText(), expression.getTextRange());
        return;
    }
    myContext.rememberVariableQualifier(qualifier.getText());
    PsiElement dotToken = expression.getDotToken();
    if (dotToken == null) {
        return;
    }
    ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.findSingle(GroovyLanguage.INSTANCE);
    for (PsiElement e = dotToken.getNextSibling(); e != null; e = e.getNextSibling()) {
        ASTNode node = e.getNode();
        if (node == null) {
            if (e instanceof PsiWhiteSpace) {
                continue;
            }
            e.accept(myVisitor);
            return;
        }
        IElementType type = node.getElementType();
        if (type == GroovyTokenTypes.mIDENT) {
            myContext.addCachedVariable(e.getText(), e.getTextRange());
        } else if (parserDefinition.getWhitespaceTokens().contains(type) || parserDefinition.getCommentTokens().contains(type)) {
            continue;
        } else {
            e.accept(myVisitor);
        }
        return;
    }
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ParserDefinition(com.intellij.lang.ParserDefinition) GrMethodCallExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression) ASTNode(com.intellij.lang.ASTNode) GrExpression(org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression) PsiElement(com.intellij.psi.PsiElement) GroovyPsiElement(org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement) PsiWhiteSpace(com.intellij.psi.PsiWhiteSpace)

Example 13 with ParserDefinition

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

the class HbFileViewProvider method createFile.

@Override
protected PsiFile createFile(@NotNull Language lang) {
    ParserDefinition parserDefinition = getDefinition(lang);
    if (parserDefinition == null) {
        return null;
    }
    if (lang.is(getTemplateDataLanguage())) {
        PsiFileImpl file = (PsiFileImpl) parserDefinition.createFile(this);
        file.setContentElementType(getTemplateDataElementType(getBaseLanguage()));
        return file;
    } else if (lang.isKindOf(getBaseLanguage())) {
        return parserDefinition.createFile(this);
    } else {
        return null;
    }
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) PsiFileImpl(com.intellij.psi.impl.source.PsiFileImpl)

Example 14 with ParserDefinition

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

the class RegExpElementImpl method isLiteralExpression.

public static boolean isLiteralExpression(@Nullable PsiElement context) {
    if (context == null)
        return false;
    final ASTNode astNode = context.getNode();
    if (astNode == null) {
        return false;
    }
    final IElementType elementType = astNode.getElementType();
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(context.getLanguage());
    return parserDefinition.getStringLiteralElements().contains(elementType);
}
Also used : IElementType(com.intellij.psi.tree.IElementType) ParserDefinition(com.intellij.lang.ParserDefinition) ASTNode(com.intellij.lang.ASTNode)

Example 15 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