Search in sources :

Example 26 with TokenSet

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

the class PyUnconditionalStatementPartFixer method doApply.

@Override
public void doApply(@NotNull Editor editor, @NotNull PySmartEnterProcessor processor, @NotNull PyElement psiElement) throws IncorrectOperationException {
    if (PyUtil.instanceOf(psiElement, PyElsePart.class, PyTryPart.class, PyFinallyPart.class)) {
        final PsiElement colon = PyPsiUtils.getFirstChildOfType(psiElement, PyTokenTypes.COLON);
        if (colon == null) {
            final TokenSet keywords = TokenSet.create(PyTokenTypes.ELSE_KEYWORD, PyTokenTypes.TRY_KEYWORD, PyTokenTypes.FINALLY_KEYWORD);
            final PsiElement keywordToken = PyPsiUtils.getChildByFilter(psiElement, keywords, 0);
            editor.getDocument().insertString(sure(keywordToken).getTextRange().getEndOffset(), ":");
        }
    }
}
Also used : TokenSet(com.intellij.psi.tree.TokenSet) PsiElement(com.intellij.psi.PsiElement)

Example 27 with TokenSet

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

the class CucumberStepReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull PsiElement element, @NotNull ProcessingContext context) {
    if (element instanceof GherkinStepImpl) {
        TokenSet textAndParamSet = TokenSet.create(GherkinTokenTypes.TEXT, GherkinTokenTypes.STEP_PARAMETER_TEXT, GherkinTokenTypes.STEP_PARAMETER_BRACE, GherkinElementTypes.STEP_PARAMETER);
        ASTNode textNode = element.getNode().findChildByType(textAndParamSet);
        textAndParamSet = TokenSet.orSet(textAndParamSet, TokenSet.create(TokenType.WHITE_SPACE));
        if (textNode != null) {
            int start = textNode.getTextRange().getStartOffset();
            int end = textNode.getTextRange().getEndOffset();
            int endBeforeSpace = end;
            textNode = textNode.getTreeNext();
            while (textNode != null && textAndParamSet.contains(textNode.getElementType())) {
                if (textNode.getElementType() == TokenType.WHITE_SPACE) {
                    endBeforeSpace = end;
                } else {
                    endBeforeSpace = textNode.getTextRange().getEndOffset();
                }
                end = textNode.getTextRange().getEndOffset();
                textNode = textNode.getTreeNext();
            }
            TextRange tr = new TextRange(start, endBeforeSpace);
            CucumberStepReference reference = new CucumberStepReference(element, tr.shiftRight(-element.getTextOffset()));
            return new PsiReference[] { reference };
        }
    }
    return PsiReference.EMPTY_ARRAY;
}
Also used : GherkinStepImpl(org.jetbrains.plugins.cucumber.psi.impl.GherkinStepImpl) TokenSet(com.intellij.psi.tree.TokenSet) ASTNode(com.intellij.lang.ASTNode) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange) NotNull(org.jetbrains.annotations.NotNull)

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