Search in sources :

Example 11 with AbstractStepDefinition

use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.

the class CucumberStepInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
    return new GherkinElementVisitor() {

        @Override
        public void visitStep(GherkinStep step) {
            super.visitStep(step);
            final PsiElement parent = step.getParent();
            if (parent instanceof GherkinStepsHolder) {
                final PsiReference[] references = step.getReferences();
                if (references.length != 1 || !(references[0] instanceof CucumberStepReference))
                    return;
                CucumberStepReference reference = (CucumberStepReference) references[0];
                final AbstractStepDefinition definition = reference.resolveToDefinition();
                if (definition == null) {
                    CucumberCreateStepFix createStepFix = null;
                    CucumberCreateAllStepsFix createAllStepsFix = null;
                    if (CucumberStepsIndex.getInstance(step.getProject()).getExtensionCount() > 0) {
                        createStepFix = new CucumberCreateStepFix();
                        createAllStepsFix = new CucumberCreateAllStepsFix();
                    }
                    holder.registerProblem(reference.getElement(), reference.getRangeInElement(), CucumberBundle.message("cucumber.inspection.undefined.step.msg.name") + " #loc #ref", createStepFix, createAllStepsFix);
                }
            }
        }
    };
}
Also used : GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) CucumberStepReference(org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiReference(com.intellij.psi.PsiReference) GherkinElementVisitor(org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 12 with AbstractStepDefinition

use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.

the class GherkinAnnotatorVisitor method visitStep.

@Override
public void visitStep(GherkinStep step) {
    final PsiReference[] references = step.getReferences();
    if (references.length != 1 || !(references[0] instanceof CucumberStepReference))
        return;
    CucumberStepReference reference = (CucumberStepReference) references[0];
    final AbstractStepDefinition definition = reference.resolveToDefinition();
    if (definition != null) {
        final List<TextRange> parameterRanges = GherkinPsiUtil.buildParameterRanges(step, definition, reference.getRangeInElement().getStartOffset());
        if (parameterRanges == null)
            return;
        for (TextRange range : parameterRanges) {
            if (range.getLength() > 0) {
                highlight(step, range, GherkinHighlighter.REGEXP_PARAMETER);
            }
        }
        highlightOutlineParams(step, reference);
    }
}
Also used : CucumberStepReference(org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange)

Aggregations

AbstractStepDefinition (org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition)12 PsiElement (com.intellij.psi.PsiElement)7 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)5 CucumberStepReference (org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference)5 PsiReference (com.intellij.psi.PsiReference)4 ArrayList (java.util.ArrayList)4 NotNull (org.jetbrains.annotations.NotNull)4 GherkinStepsHolder (org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder)4 TextRange (com.intellij.openapi.util.TextRange)3 PsiFile (com.intellij.psi.PsiFile)3 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 JavaStepDefinition (org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition)2 GherkinFeature (org.jetbrains.plugins.cucumber.psi.GherkinFeature)2 GherkinFile (org.jetbrains.plugins.cucumber.psi.GherkinFile)2 LookupElementBuilder (com.intellij.codeInsight.lookup.LookupElementBuilder)1 ASTNode (com.intellij.lang.ASTNode)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 Module (com.intellij.openapi.module.Module)1 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1