use of org.jetbrains.plugins.cucumber.psi.GherkinFile 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);
}
}
}
}
}
}
}
use of org.jetbrains.plugins.cucumber.psi.GherkinFile in project intellij-plugins by JetBrains.
the class CucumberCreateStepFixBase method applyFix.
public void applyFix(@NotNull final Project project, @NotNull ProblemDescriptor descriptor) {
final GherkinStep step = (GherkinStep) descriptor.getPsiElement();
final GherkinFile featureFile = (GherkinFile) step.getContainingFile();
// TODO + step defs pairs from other content roots
final List<Pair<PsiFile, BDDFrameworkType>> pairs = ContainerUtil.newArrayList(getStepDefinitionContainers(featureFile));
if (!pairs.isEmpty()) {
pairs.add(0, null);
final JBPopupFactory popupFactory = JBPopupFactory.getInstance();
final ListPopup popupStep = popupFactory.createListPopup(new BaseListPopupStep<Pair<PsiFile, BDDFrameworkType>>(CucumberBundle.message("choose.step.definition.file"), ContainerUtil.newArrayList(pairs)) {
@Override
public boolean isSpeedSearchEnabled() {
return true;
}
@NotNull
@Override
public String getTextFor(Pair<PsiFile, BDDFrameworkType> value) {
if (value == null) {
return CucumberBundle.message("create.new.file");
}
final VirtualFile file = value.getFirst().getVirtualFile();
assert file != null;
CucumberStepsIndex stepsIndex = CucumberStepsIndex.getInstance(value.getFirst().getProject());
StepDefinitionCreator stepDefinitionCreator = stepsIndex.getExtensionMap().get(value.getSecond()).getStepDefinitionCreator();
return stepDefinitionCreator.getStepDefinitionFilePath(value.getFirst());
}
@Override
public Icon getIconFor(Pair<PsiFile, BDDFrameworkType> value) {
return value == null ? AllIcons.Actions.CreateFromUsage : value.getFirst().getIcon(0);
}
@Override
public PopupStep onChosen(final Pair<PsiFile, BDDFrameworkType> selectedValue, boolean finalChoice) {
return doFinalStep(() -> createStepOrSteps(step, selectedValue));
}
});
if (!ApplicationManager.getApplication().isUnitTestMode()) {
popupStep.showCenteredInCurrentWindow(step.getProject());
} else {
createStepOrSteps(step, pairs.get(1));
}
} else {
createFileOrStepDefinition(step, null);
}
}
Aggregations