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;
}
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);
}
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() : "");
}
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();
}
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);
}
}
}
}
}
}
}
Aggregations