Search in sources :

Example 1 with GherkinFile

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;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) NullableComputable(com.intellij.openapi.util.NullableComputable) PsiFile(com.intellij.psi.PsiFile) PsiElementVisitor(com.intellij.psi.PsiElementVisitor) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile)

Example 2 with GherkinFile

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;
}
Also used : GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiElement(com.intellij.psi.PsiElement) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with GherkinFile

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();
}
Also used : ArrayList(java.util.ArrayList) GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) CucumberStepsIndex(org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) GherkinStepsHolder(org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder) PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) PsiElement(com.intellij.psi.PsiElement) GherkinFeature(org.jetbrains.plugins.cucumber.psi.GherkinFeature) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GherkinFile

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;
}
Also used : GherkinStep(org.jetbrains.plugins.cucumber.psi.GherkinStep) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile)

Example 5 with GherkinFile

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;
}
Also used : Document(com.intellij.openapi.editor.Document) GherkinFile(org.jetbrains.plugins.cucumber.psi.GherkinFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

GherkinFile (org.jetbrains.plugins.cucumber.psi.GherkinFile)7 PsiFile (com.intellij.psi.PsiFile)4 GherkinStep (org.jetbrains.plugins.cucumber.psi.GherkinStep)4 PsiElement (com.intellij.psi.PsiElement)3 GherkinStepsHolder (org.jetbrains.plugins.cucumber.psi.GherkinStepsHolder)3 NotNull (org.jetbrains.annotations.NotNull)2 GherkinFeature (org.jetbrains.plugins.cucumber.psi.GherkinFeature)2 AbstractStepDefinition (org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition)2 CucumberStepsIndex (org.jetbrains.plugins.cucumber.steps.CucumberStepsIndex)2 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 Document (com.intellij.openapi.editor.Document)1 JBPopupFactory (com.intellij.openapi.ui.popup.JBPopupFactory)1 ListPopup (com.intellij.openapi.ui.popup.ListPopup)1 PopupStep (com.intellij.openapi.ui.popup.PopupStep)1 BaseListPopupStep (com.intellij.openapi.ui.popup.util.BaseListPopupStep)1 NullableComputable (com.intellij.openapi.util.NullableComputable)1 Pair (com.intellij.openapi.util.Pair)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1