use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class GrCucumberExtension method getGlues.
@NotNull
@Override
public Collection<String> getGlues(@NotNull GherkinFile file, Set<String> gluesFromOtherFiles) {
if (gluesFromOtherFiles == null) {
gluesFromOtherFiles = ContainerUtil.newHashSet();
}
final Set<String> glues = gluesFromOtherFiles;
for (AbstractStepDefinition stepDefinition : getAllStepDefinitions(file.getProject())) {
final PsiElement stepDefinitionElement = stepDefinition.getElement();
final String glue = getGlue(stepDefinitionElement);
if (glue != null) {
glues.add(glue);
}
}
return glues;
}
use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class CucumberStepRenameDialog method getSuggestedNames.
@Override
public String[] getSuggestedNames() {
AbstractStepDefinition stepDefinition = getStepDefinition();
if (stepDefinition != null) {
String result = stepDefinition.getCucumberRegex();
if (result != null) {
result = StringUtil.trimStart(result, "^");
result = StringUtil.trimEnd(result, "$");
return new String[] { result };
}
}
return super.getSuggestedNames();
}
use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition 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.steps.AbstractStepDefinition 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.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class CucumberCompletionContributor method addStepDefinitions.
private static void addStepDefinitions(CompletionResultSet result, PsiFile file) {
result = result.withPrefixMatcher(new CucumberPrefixMatcher(result.getPrefixMatcher().getPrefix()));
final List<AbstractStepDefinition> definitions = CucumberStepsIndex.getInstance(file.getProject()).getAllStepDefinitions(file);
for (AbstractStepDefinition definition : definitions) {
String text = definition.getCucumberRegex();
if (text != null) {
// trim regexp line start/end markers
text = StringUtil.trimStart(text, "^");
text = StringUtil.trimEnd(text, "$");
text = StringUtil.replace(text, "\\\"", "\"");
for (Map.Entry<String, String> group : GROUP_TYPE_MAP.entrySet()) {
text = StringUtil.replace(text, group.getKey(), group.getValue());
}
for (Map.Entry<String, String> group : INTERPOLATION_PARAMETERS_MAP.entrySet()) {
text = text.replaceAll(group.getKey(), group.getValue());
}
final List<TextRange> ranges = new ArrayList<>();
Matcher m = QUESTION_MARK_PATTERN.matcher(text);
if (m.find()) {
text = m.replaceAll("$1");
}
m = POSSIBLE_GROUP_PATTERN.matcher(text);
while (m.find()) {
text = m.replaceAll("$1");
}
m = PARAMETERS_PATTERN.matcher(text);
while (m.find()) {
ranges.add(new TextRange(m.start(), m.end()));
}
final PsiElement element = definition.getElement();
final LookupElementBuilder lookup = element != null ? LookupElementBuilder.create(element, text).bold() : LookupElementBuilder.create(text);
result.addElement(lookup.withInsertHandler(new StepInsertHandler(ranges)));
}
}
}
Aggregations