Search in sources :

Example 1 with GherkinElementVisitor

use of org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor in project intellij-plugins by JetBrains.

the class CucumberExamplesColonInspection method buildVisitor.

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

        @Override
        public void visitExamplesBlock(GherkinExamplesBlockImpl block) {
            final PsiElement examples = block.getFirstChild();
            assert examples != null;
            final PsiElement next = examples.getNextSibling();
            final String text = next != null ? next.getText() : null;
            if (text == null || !text.contains(":")) {
                holder.registerProblem(examples, new TextRange(0, examples.getTextRange().getEndOffset() - examples.getTextOffset()), CucumberBundle.message("inspection.missed.colon.example.name"), new CucumberAddExamplesColonFix());
            }
        }
    };
}
Also used : GherkinExamplesBlockImpl(org.jetbrains.plugins.cucumber.psi.impl.GherkinExamplesBlockImpl) GherkinElementVisitor(org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor) TextRange(com.intellij.openapi.util.TextRange) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GherkinElementVisitor

use of org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor in project intellij-plugins by JetBrains.

the class CucumberMissedExamplesInspection method buildVisitor.

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

        @Override
        public void visitScenarioOutline(GherkinScenarioOutline outline) {
            super.visitScenarioOutline(outline);
            final GherkinExamplesBlockImpl block = PsiTreeUtil.getChildOfType(outline, GherkinExamplesBlockImpl.class);
            if (block == null) {
                ASTNode[] keyword = outline.getNode().getChildren(GherkinTokenTypes.KEYWORDS);
                if (keyword.length > 0) {
                    holder.registerProblem(outline, keyword[0].getTextRange().shiftRight(-outline.getTextOffset()), CucumberBundle.message("inspection.missed.example.msg.name"), new CucumberCreateExamplesSectionFix());
                }
            }
        }
    };
}
Also used : GherkinExamplesBlockImpl(org.jetbrains.plugins.cucumber.psi.impl.GherkinExamplesBlockImpl) ASTNode(com.intellij.lang.ASTNode) GherkinElementVisitor(org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor) GherkinScenarioOutline(org.jetbrains.plugins.cucumber.psi.GherkinScenarioOutline) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with GherkinElementVisitor

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

Aggregations

NotNull (org.jetbrains.annotations.NotNull)3 GherkinElementVisitor (org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor)3 PsiElement (com.intellij.psi.PsiElement)2 GherkinExamplesBlockImpl (org.jetbrains.plugins.cucumber.psi.impl.GherkinExamplesBlockImpl)2 ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 PsiReference (com.intellij.psi.PsiReference)1 GherkinScenarioOutline (org.jetbrains.plugins.cucumber.psi.GherkinScenarioOutline)1 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)1 GherkinStepsHolder (org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder)1 AbstractStepDefinition (org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition)1 CucumberStepReference (org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference)1