use of org.jetbrains.plugins.cucumber.psi.GherkinStep in project intellij-plugins by JetBrains.
the class CucumberStepRenameProcessor method renameElement.
@Override
public void renameElement(PsiElement element, String newName, UsageInfo[] usages, @Nullable RefactoringElementListener listener) throws IncorrectOperationException {
final CucumberStepReference reference = getCucumberStepReference(element);
if (reference != null) {
final AbstractStepDefinition stepDefinition = reference.resolveToDefinition();
if (stepDefinition != null) {
final PsiElement elementToRename = stepDefinition.getElement();
final List<String> newStaticTexts = prepareRegexAndGetStaticTexts(newName);
final String oldStepDefPatternText = stepDefinition.getCucumberRegex();
if (oldStepDefPatternText != null) {
final Pattern oldStepDefPattern = Pattern.compile(prepareRegexAndGetStaticTexts(oldStepDefPatternText).get(0));
for (UsageInfo usage : usages) {
final PsiElement possibleStep = usage.getElement();
if (possibleStep instanceof GherkinStep) {
final String oldStepName = ((GherkinStep) possibleStep).getStepName();
final String newStepName = getNewStepName(oldStepName, oldStepDefPattern, newStaticTexts);
((GherkinStep) possibleStep).setName(newStepName);
}
}
final String prefix = oldStepDefPatternText.startsWith("^") ? "^" : "";
final String suffix = oldStepDefPatternText.endsWith("$") ? "$" : "";
stepDefinition.setCucumberRegex(prefix + newName + suffix);
if (listener != null && elementToRename != null) {
listener.elementRenamed(elementToRename);
}
}
}
}
}
use of org.jetbrains.plugins.cucumber.psi.GherkinStep in project intellij-plugins by JetBrains.
the class AbstractStepDefinition method findSteps.
/**
* Finds all steps points to this definition in some scope
*
* @param searchScope scope to find steps
* @return steps
*/
@NotNull
public Collection<GherkinStep> findSteps(@NotNull final SearchScope searchScope) {
final String regex = getCucumberRegex();
final PsiElement element = getElement();
if ((regex == null) || (element == null)) {
return Collections.emptyList();
}
final CollectProcessor<PsiReference> consumer = new CollectProcessor<>();
CucumberUtil.findGherkinReferencesToElement(element, regex, consumer, searchScope);
// We use hash to get rid of duplicates
final Collection<GherkinStep> results = new HashSet<>(consumer.getResults().size());
for (final PsiReference reference : consumer.getResults()) {
final PsiElement step = reference.getElement();
if (step instanceof GherkinStep) {
results.add((GherkinStep) step);
}
}
return results;
}
use of org.jetbrains.plugins.cucumber.psi.GherkinStep in project intellij-plugins by JetBrains.
the class Java8StepDefinitionCreator method buildStepDefinitionByStep.
private static PsiElement buildStepDefinitionByStep(@NotNull final GherkinStep step, Language language) {
final Step cucumberStep = new Step(new ArrayList<>(), step.getKeyword().getText(), step.getStepName(), 0, null, null);
final SnippetGenerator generator = new SnippetGenerator(new Java8Snippet());
final String snippet = generator.getSnippet(cucumberStep, new FunctionNameGenerator(new CamelCaseConcatenator())).replace("PendingException", CucumberJavaUtil.getCucumberPendingExceptionFqn(step)).replaceAll("\\\\\\\\", "\\\\").replaceAll("\\\\d", "\\\\\\\\d");
JVMElementFactory factory = JVMElementFactories.requireFactory(language, step.getProject());
return factory.createExpressionFromText(snippet, step);
}
use of org.jetbrains.plugins.cucumber.psi.GherkinStep 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.GherkinStep in project intellij-plugins by JetBrains.
the class AnnotationPackageProviderTest method createStepIn.
private static GherkinStep createStepIn(String language) {
GherkinFile featureFile = EasyMock.createNiceMock(GherkinFile.class);
expect(featureFile.getLocaleLanguage()).andReturn(language).anyTimes();
GherkinStep step = EasyMock.createNiceMock(GherkinStep.class);
expect(step.getContainingFile()).andReturn(featureFile).anyTimes();
replay(featureFile, step);
return step;
}
Aggregations