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