Search in sources :

Example 11 with TokenSet

use of com.intellij.psi.tree.TokenSet in project intellij-community by JetBrains.

the class ShiftIndentInsideHelper method isComment.

private static boolean isComment(final ASTNode node) {
    final PsiElement psiElement = SourceTreeToPsiMap.treeElementToPsi(node);
    if (psiElement instanceof PsiComment)
        return true;
    final ParserDefinition parserDefinition = LanguageParserDefinitions.INSTANCE.forLanguage(psiElement.getLanguage());
    if (parserDefinition == null)
        return false;
    final TokenSet commentTokens = parserDefinition.getCommentTokens();
    return commentTokens.contains(node.getElementType());
}
Also used : ParserDefinition(com.intellij.lang.ParserDefinition) TokenSet(com.intellij.psi.tree.TokenSet)

Example 12 with TokenSet

use of com.intellij.psi.tree.TokenSet 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 13 with TokenSet

use of com.intellij.psi.tree.TokenSet in project intellij-plugins by JetBrains.

the class OgnlKeywordCompletionContributor method installBooleanNull.

private void installBooleanNull() {
    final TokenSet precedingOperators = TokenSet.create(OgnlTypes.EQUAL, OgnlTypes.EQ_KEYWORD, OgnlTypes.NOT_EQUAL, OgnlTypes.NEQ_KEYWORD, OgnlTypes.QUESTION, OgnlTypes.COLON, OgnlTypes.AND_KEYWORD, OgnlTypes.AND_AND, OgnlTypes.OR_KEYWORD, OgnlTypes.OR_OR, OgnlTypes.NEGATE, OgnlTypes.NOT_KEYWORD, OgnlTypes.EQ);
    extendKeywordCompletion(psiElement().afterLeaf(psiElement().inside(OgnlExpression.class).withElementType(precedingOperators)), FALSE, TRUE, NULL);
}
Also used : TokenSet(com.intellij.psi.tree.TokenSet)

Example 14 with TokenSet

use of com.intellij.psi.tree.TokenSet in project intellij-plugins by JetBrains.

the class CucumberStepRenameProcessor method prepareRegexAndGetStaticTexts.

/**
   * Wraps all special symbols of regexp with group and cut static text.
   * @param source regex to work with
   * @return List of strings. The first one is prepared regex, then static elements of the regex
   */
@NotNull
public static List<String> prepareRegexAndGetStaticTexts(@NotNull final String source) {
    final ArrayList<String> result = new ArrayList<>();
    final StringBuilder preparedRegexp = new StringBuilder();
    final RegExpLexer lexer = new RegExpLexer(EnumSet.noneOf(RegExpCapability.class));
    lexer.start(source);
    IElementType previous = null;
    final TokenSet toSkip = TokenSet.create(RegExpTT.CHARACTER, RegExpTT.CARET, RegExpTT.DOLLAR);
    StringBuilder currentStaticText = new StringBuilder();
    boolean insideAddedGroup = false;
    final Stack<IElementType> elementsWaitingToClose = new Stack<>();
    while (lexer.getTokenType() != null) {
        if (!toSkip.contains(lexer.getTokenType())) {
            if (!insideAddedGroup) {
                insideAddedGroup = true;
                preparedRegexp.append('(');
                result.add(currentStaticText.toString());
                currentStaticText = new StringBuilder();
            }
            if (lexer.getTokenType() == RegExpTT.GROUP_BEGIN || lexer.getTokenType() == RegExpTT.NON_CAPT_GROUP) {
                elementsWaitingToClose.push(RegExpTT.GROUP_END);
            } else if (lexer.getTokenType() == RegExpTT.CLASS_BEGIN) {
                elementsWaitingToClose.push(RegExpTT.CLASS_END);
            } else if (elementsWaitingToClose.size() > 0 && lexer.getTokenType() == elementsWaitingToClose.peek()) {
                elementsWaitingToClose.pop();
            }
        } else {
            if (elementsWaitingToClose.size() == 0) {
                if (previous != null && previous != RegExpTT.CHARACTER && insideAddedGroup) {
                    insideAddedGroup = false;
                    preparedRegexp.append(')');
                }
                if (lexer.getTokenType() == RegExpTT.CHARACTER) {
                    currentStaticText.append(lexer.getTokenText());
                }
            }
        }
        preparedRegexp.append(lexer.getTokenText());
        if (lexer.getTokenType() == RegExpTT.GROUP_BEGIN) {
            //Making all group in the regex non capturing
            preparedRegexp.append("?:");
        }
        previous = lexer.getTokenType();
        lexer.advance();
    }
    if (insideAddedGroup) {
        preparedRegexp.append(')');
    }
    result.add(currentStaticText.toString());
    result.add(0, preparedRegexp.toString());
    return result;
}
Also used : IElementType(com.intellij.psi.tree.IElementType) TokenSet(com.intellij.psi.tree.TokenSet) RegExpCapability(org.intellij.lang.regexp.RegExpCapability) RegExpLexer(org.intellij.lang.regexp.RegExpLexer) NotNull(org.jetbrains.annotations.NotNull)

Example 15 with TokenSet

use of com.intellij.psi.tree.TokenSet in project WebStormRequireJsPlugin by Fedott.

the class RequirejsProjectComponent method parsePackages.

private void parsePackages(TreeElement node) {
    TokenSet tokenSet = TokenSet.create(JSElementTypes.OBJECT_LITERAL_EXPRESSION, JSElementTypes.LITERAL_EXPRESSION);
    TreeElement packageNode = (TreeElement) node.findChildByType(tokenSet);
    parsePackage(packageNode);
}
Also used : TokenSet(com.intellij.psi.tree.TokenSet) TreeElement(com.intellij.psi.impl.source.tree.TreeElement)

Aggregations

TokenSet (com.intellij.psi.tree.TokenSet)27 ParserDefinition (com.intellij.lang.ParserDefinition)6 PsiBuilder (com.intellij.lang.PsiBuilder)6 IElementType (com.intellij.psi.tree.IElementType)6 Language (com.intellij.lang.Language)4 ASTNode (com.intellij.lang.ASTNode)3 PsiElement (com.intellij.psi.PsiElement)3 NotNull (org.jetbrains.annotations.NotNull)3 Nullable (org.jetbrains.annotations.Nullable)3 Lexer (com.intellij.lexer.Lexer)2 CustomSyntaxTableFileType (com.intellij.openapi.fileTypes.impl.CustomSyntaxTableFileType)2 TreeElement (com.intellij.psi.impl.source.tree.TreeElement)2 Document (com.intellij.openapi.editor.Document)1 TextAttributesKey (com.intellij.openapi.editor.colors.TextAttributesKey)1 FileType (com.intellij.openapi.fileTypes.FileType)1 LanguageFileType (com.intellij.openapi.fileTypes.LanguageFileType)1 SyntaxHighlighter (com.intellij.openapi.fileTypes.SyntaxHighlighter)1 AbstractFileType (com.intellij.openapi.fileTypes.impl.AbstractFileType)1 Computable (com.intellij.openapi.util.Computable)1 TextRange (com.intellij.openapi.util.TextRange)1