Search in sources :

Example 1 with GherkinStepImpl

use of org.jetbrains.plugins.cucumber.psi.impl.GherkinStepImpl 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

ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 TokenSet (com.intellij.psi.tree.TokenSet)1 NotNull (org.jetbrains.annotations.NotNull)1 GherkinStepImpl (org.jetbrains.plugins.cucumber.psi.impl.GherkinStepImpl)1