use of org.jetbrains.plugins.cucumber.psi.GherkinFile in project intellij-plugins by JetBrains.
the class CucumberJavaAllFeaturesInFolderRunConfigurationProducer method getStepsGlue.
@Override
protected NullableComputable<String> getStepsGlue(@NotNull final PsiElement element) {
final Set<String> glues = getHookGlue(element);
if (element instanceof PsiDirectory) {
final PsiDirectory dir = (PsiDirectory) element;
final CucumberJvmExtensionPoint[] extensions = Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME);
return new NullableComputable<String>() {
@Nullable
@Override
public String compute() {
dir.accept(new PsiElementVisitor() {
@Override
public void visitFile(final PsiFile file) {
if (file instanceof GherkinFile) {
for (CucumberJvmExtensionPoint extension : extensions) {
extension.getGlues((GherkinFile) file, glues);
}
}
}
@Override
public void visitDirectory(PsiDirectory dir) {
for (PsiDirectory subDir : dir.getSubdirectories()) {
subDir.accept(this);
}
for (PsiFile file : dir.getFiles()) {
file.accept(this);
}
}
});
return StringUtil.join(glues, " ");
}
};
}
return null;
}
use of org.jetbrains.plugins.cucumber.psi.GherkinFile in project intellij-plugins by JetBrains.
the class CucumberJavaFeatureRunConfigurationProducer method getFileToRun.
@Nullable
@Override
protected VirtualFile getFileToRun(ConfigurationContext context) {
final PsiElement element = context.getPsiLocation();
final GherkinStepsHolder scenario = PsiTreeUtil.getParentOfType(element, GherkinScenario.class, GherkinScenarioOutline.class);
if (element != null && scenario == null && element.getContainingFile() instanceof GherkinFile) {
return element.getContainingFile().getVirtualFile();
}
return null;
}
use of org.jetbrains.plugins.cucumber.psi.GherkinFile 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.GherkinFile 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;
}
use of org.jetbrains.plugins.cucumber.psi.GherkinFile in project intellij-plugins by JetBrains.
the class CucumberEnterHandler method preprocessEnter.
public Result preprocessEnter(@NotNull PsiFile file, @NotNull Editor editor, @NotNull Ref<Integer> caretOffset, @NotNull Ref<Integer> caretAdvance, @NotNull DataContext dataContext, EditorActionHandler originalHandler) {
if (!(file instanceof GherkinFile)) {
return Result.Continue;
}
int caretOffsetValue = caretOffset.get().intValue();
if (caretOffsetValue < 3) {
return Result.Continue;
}
final Document document = editor.getDocument();
final String docText = document.getText();
PsiDocumentManager.getInstance(file.getProject()).commitDocument(editor.getDocument());
final PsiElement probableQuotes = file.findElementAt(caretOffsetValue - 1);
if (probableQuotes != null && probableQuotes.getNode().getElementType() == GherkinTokenTypes.PYSTRING) {
final PsiElement probablePyStringText = document.getTextLength() == PYSTRING_QUOTES.length() ? null : file.findElementAt(caretOffsetValue - 1 - PYSTRING_QUOTES.length());
if (probablePyStringText == null || probablePyStringText.getNode().getElementType() != GherkinTokenTypes.PYSTRING_TEXT) {
int line = document.getLineNumber(caretOffsetValue);
int lineStart = document.getLineStartOffset(line);
int textStart = CharArrayUtil.shiftForward(docText, lineStart, " \t");
final String space = docText.subSequence(lineStart, textStart).toString();
// insert closing triple quote
EditorModificationUtil.insertStringAtCaret(editor, "\n" + space + "\n" + space + PYSTRING_QUOTES);
editor.getCaretModel().moveCaretRelatively(-3, -1, false, false, true);
return Result.Stop;
}
}
return Result.Continue;
}
Aggregations