use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class GherkinAnnotatorVisitor method visitStep.
@Override
public void visitStep(GherkinStep step) {
final PsiReference[] references = step.getReferences();
if (references.length != 1 || !(references[0] instanceof CucumberStepReference))
return;
CucumberStepReference reference = (CucumberStepReference) references[0];
final AbstractStepDefinition definition = reference.resolveToDefinition();
if (definition != null) {
final List<TextRange> parameterRanges = GherkinPsiUtil.buildParameterRanges(step, definition, reference.getRangeInElement().getStartOffset());
if (parameterRanges == null)
return;
for (TextRange range : parameterRanges) {
if (range.getLength() > 0) {
highlight(step, range, GherkinHighlighter.REGEXP_PARAMETER);
}
}
highlightOutlineParams(step, reference);
}
}
use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition 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.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class GherkinStepParameterSelectioner method select.
@NotNull
@Override
public List<TextRange> select(@NotNull final PsiElement e, @NotNull final CharSequence editorText, final int cursorOffset, @NotNull final Editor editor) {
final List<TextRange> result = new ArrayList<>();
if (editor.getSettings().isCamelWords()) {
result.addAll(super.select(e, editorText, cursorOffset, editor));
}
final PsiElement parent = e.getParent();
if (parent instanceof GherkinStep) {
final GherkinStep step = (GherkinStep) parent;
for (final PsiReference reference : step.getReferences()) {
if (reference instanceof CucumberStepReference && !DumbService.isDumb(step.getProject())) {
final AbstractStepDefinition definition = ((CucumberStepReference) reference).resolveToDefinition();
if (definition != null) {
final List<TextRange> ranges = GherkinPsiUtil.buildParameterRanges(step, definition, step.getTextOffset() + reference.getRangeInElement().getStartOffset());
if (ranges != null) {
result.addAll(ranges);
result.addAll(buildAdditionalRanges(ranges, editorText));
}
}
}
}
buildAdditionalRanges(result, editorText);
} else if (parent instanceof GherkinStepsHolder) {
final ASTNode stepHolderNode = parent.getNode();
if (stepHolderNode != null) {
final ASTNode keyword = stepHolderNode.findChildByType(GherkinTokenTypes.KEYWORDS);
if (keyword != null) {
result.add(TextRange.create(keyword.getTextRange().getStartOffset(), parent.getTextRange().getEndOffset()));
}
}
result.add(parent.getTextRange());
}
return result;
}
use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class CucumberStepInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, final boolean isOnTheFly) {
return new GherkinElementVisitor() {
@Override
public void visitStep(GherkinStep step) {
super.visitStep(step);
final PsiElement parent = step.getParent();
if (parent instanceof GherkinStepsHolder) {
final PsiReference[] references = step.getReferences();
if (references.length != 1 || !(references[0] instanceof CucumberStepReference))
return;
CucumberStepReference reference = (CucumberStepReference) references[0];
final AbstractStepDefinition definition = reference.resolveToDefinition();
if (definition == null) {
CucumberCreateStepFix createStepFix = null;
CucumberCreateAllStepsFix createAllStepsFix = null;
if (CucumberStepsIndex.getInstance(step.getProject()).getExtensionCount() > 0) {
createStepFix = new CucumberCreateStepFix();
createAllStepsFix = new CucumberCreateAllStepsFix();
}
holder.registerProblem(reference.getElement(), reference.getRangeInElement(), CucumberBundle.message("cucumber.inspection.undefined.step.msg.name") + " #loc #ref", createStepFix, createAllStepsFix);
}
}
}
};
}
use of org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition in project intellij-plugins by JetBrains.
the class CucumberJavaExtension method loadStepsFor.
@Override
public List<AbstractStepDefinition> loadStepsFor(@Nullable PsiFile featureFile, @NotNull Module module) {
final GlobalSearchScope dependenciesScope = module.getModuleWithDependenciesAndLibrariesScope(true);
PsiClass stepDefAnnotationClass = JavaPsiFacade.getInstance(module.getProject()).findClass(CUCUMBER_RUNTIME_JAVA_STEP_DEF_ANNOTATION, dependenciesScope);
if (stepDefAnnotationClass == null) {
return Collections.emptyList();
}
final List<AbstractStepDefinition> result = new ArrayList<>();
final Query<PsiClass> stepDefAnnotations = AnnotatedElementsSearch.searchPsiClasses(stepDefAnnotationClass, dependenciesScope);
for (PsiClass annotationClass : stepDefAnnotations) {
if (annotationClass.isAnnotationType()) {
final Query<PsiMethod> javaStepDefinitions = AnnotatedElementsSearch.searchPsiMethods(annotationClass, dependenciesScope);
for (PsiMethod stepDefMethod : javaStepDefinitions) {
result.add(new JavaStepDefinition(stepDefMethod));
}
}
}
return result;
}
Aggregations