Search in sources :

Example 1 with GherkinStepsHolder

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

the class CucumberJavaFeatureRunConfigurationProducer method getFileToRun.

@Nullable
@Override
protected VirtualFile getFileToRun(ConfigurationContext context) {
    final PsiElement element = context.getPsiLocation();
    final GherkinStepsHolder scenario = PsiTreeUtil.getParentOfType(element, GherkinScenario.class, GherkinScenarioOutline.class);
    if (element != null && scenario == null && element.getContainingFile() instanceof GherkinFile) {
        return element.getContainingFile().getVirtualFile();
    }
    return null;
}
Also used : GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiElement(com.intellij.psi.PsiElement) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with GherkinStepsHolder

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

the class CucumberJavaScenarioRunConfigurationProducer method getNameFilter.

@Override
protected String getNameFilter(@NotNull ConfigurationContext context) {
    final PsiElement sourceElement = context.getPsiLocation();
    final GherkinStepsHolder scenario = PsiTreeUtil.getParentOfType(sourceElement, GherkinScenario.class, GherkinScenarioOutline.class);
    if (scenario != null) {
        return "^" + StringUtil.escapeToRegexp(scenario.getScenarioName()) + "$";
    }
    return super.getNameFilter(context);
}
Also used : GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiElement(com.intellij.psi.PsiElement)

Example 3 with GherkinStepsHolder

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

the class CucumberJavaScenarioRunConfigurationProducer method getConfigurationName.

@Override
protected String getConfigurationName(@NotNull final ConfigurationContext context) {
    final PsiElement sourceElement = context.getPsiLocation();
    final GherkinStepsHolder scenario = PsiTreeUtil.getParentOfType(sourceElement, GherkinScenario.class, GherkinScenarioOutline.class);
    return "Scenario: " + (scenario != null ? scenario.getScenarioName() : "");
}
Also used : GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiElement(com.intellij.psi.PsiElement)

Example 4 with GherkinStepsHolder

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

the class CucumberGoToRelatedProvider method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement) {
    final PsiFile file = psiElement.getContainingFile();
    if (file instanceof GherkinFile) {
        final List<GherkinStep> steps = new ArrayList<>();
        final GherkinFile gherkinFile = (GherkinFile) file;
        final GherkinFeature[] features = gherkinFile.getFeatures();
        for (GherkinFeature feature : features) {
            final GherkinStepsHolder[] stepHolders = feature.getScenarios();
            for (GherkinStepsHolder stepHolder : stepHolders) {
                Collections.addAll(steps, stepHolder.getSteps());
            }
        }
        final CucumberStepsIndex index = CucumberStepsIndex.getInstance(file.getProject());
        final List<PsiFile> resultFiles = new ArrayList<>();
        final List<GotoRelatedItem> result = new ArrayList<>();
        for (GherkinStep step : steps) {
            AbstractStepDefinition stepDef = index.findStepDefinition(gherkinFile, step);
            final PsiElement stepDefMethod = stepDef != null ? stepDef.getElement() : null;
            if (stepDefMethod != null) {
                final PsiFile stepDefFile = stepDefMethod.getContainingFile();
                if (!resultFiles.contains(stepDefFile)) {
                    resultFiles.add(stepDefFile);
                    result.add(new GotoRelatedItem(stepDefFile, "Step definition file"));
                }
            }
        }
        return result;
    }
    return Collections.emptyList();
}
Also used : ArrayList(java.util.ArrayList) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) CucumberStepsIndex(org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) PsiElement(com.intellij.psi.PsiElement) GherkinFeature(org.jetbrains.plugins.cucumber.psi.GherkinFeature) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GherkinStepsHolder

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

the class CucumberCreateAllStepsFix method createStepOrSteps.

@Override
protected void createStepOrSteps(GherkinStep sourceStep, @Nullable final Pair<PsiFile, BDDFrameworkType> fileAndFrameworkType) {
    final PsiFile probableGherkinFile = sourceStep.getContainingFile();
    if (!(probableGherkinFile instanceof GherkinFile)) {
        return;
    }
    final Set<String> createdStepDefPatterns = new HashSet<>();
    final GherkinFile gherkinFile = (GherkinFile) probableGherkinFile;
    for (GherkinFeature feature : gherkinFile.getFeatures()) {
        for (GherkinStepsHolder stepsHolder : feature.getScenarios()) {
            for (GherkinStep step : stepsHolder.getSteps()) {
                final PsiReference[] references = step.getReferences();
                for (PsiReference reference : references) {
                    if (!(reference instanceof CucumberStepReference))
                        continue;
                    final AbstractStepDefinition definition = ((CucumberStepReference) reference).resolveToDefinition();
                    if (definition == null) {
                        String pattern = Pattern.quote(step.getStepName());
                        pattern = StringUtil.trimEnd(StringUtil.trimStart(pattern, "\\Q"), "\\E");
                        pattern = CucumberUtil.prepareStepRegexp(pattern);
                        if (!createdStepDefPatterns.contains(pattern)) {
                            createFileOrStepDefinition(step, fileAndFrameworkType);
                            createdStepDefPatterns.add(pattern);
                        }
                    }
                }
            }
        }
    }
}
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) PsiFile(com.intellij.psi.PsiFile) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) HashSet(java.util.HashSet) GherkinFeature(org.jetbrains.plugins.cucumber.psi.GherkinFeature)

Aggregations

GherkinStepsHolder (org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder)8 PsiElement (com.intellij.psi.PsiElement)7 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)4 AbstractStepDefinition (org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition)4 PsiFile (com.intellij.psi.PsiFile)3 PsiReference (com.intellij.psi.PsiReference)3 NotNull (org.jetbrains.annotations.NotNull)3 GherkinFile (org.jetbrains.plugins.cucumber.psi.GherkinFile)3 CucumberStepReference (org.jetbrains.plugins.cucumber.steps.reference.CucumberStepReference)3 ArrayList (java.util.ArrayList)2 Nullable (org.jetbrains.annotations.Nullable)2 GherkinFeature (org.jetbrains.plugins.cucumber.psi.GherkinFeature)2 ASTNode (com.intellij.lang.ASTNode)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 TextRange (com.intellij.openapi.util.TextRange)1 HashSet (java.util.HashSet)1 GherkinElementVisitor (org.jetbrains.plugins.cucumber.psi.GherkinElementVisitor)1 CucumberStepsIndex (org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex)1