Search in sources :

Example 1 with CucumberJvmExtensionPoint

use of org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint 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 CucumberJvmExtensionPoint

use of org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint in project intellij-plugins by JetBrains.

the class CucumberStepsIndex method isStepLikeFile.

private boolean isStepLikeFile(PsiElement child, PsiElement parent) {
    if (child instanceof PsiFile) {
        final PsiFile file = (PsiFile) child;
        CucumberJvmExtensionPoint ep = myExtensionMap.get(new BDDFrameworkType(file.getFileType()));
        return ep != null && ep.isStepLikeFile(file, parent);
    }
    return false;
}
Also used : CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) PsiFile(com.intellij.psi.PsiFile) BDDFrameworkType(org.jetbrains.plugins.cucumber.BDDFrameworkType)

Example 3 with CucumberJvmExtensionPoint

use of org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint in project intellij-plugins by JetBrains.

the class CucumberStepsIndex method getStepDefinitionContainers.

public Set<Pair<PsiFile, BDDFrameworkType>> getStepDefinitionContainers(@NotNull final GherkinFile featureFile) {
    Set<Pair<PsiFile, BDDFrameworkType>> result = new HashSet<>();
    for (CucumberJvmExtensionPoint ep : myExtensionMap.values()) {
        // Skip if framework file creation support is optional
        if ((ep instanceof OptionalStepDefinitionExtensionPoint) && !((OptionalStepDefinitionExtensionPoint) ep).participateInStepDefinitionCreation(featureFile)) {
            continue;
        }
        final Collection<? extends PsiFile> psiFiles = ep.getStepDefinitionContainers(featureFile);
        final BDDFrameworkType frameworkType = ep.getStepFileType();
        for (final PsiFile psiFile : psiFiles) {
            result.add(Pair.create(psiFile, frameworkType));
        }
    }
    return result;
}
Also used : CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) BDDFrameworkType(org.jetbrains.plugins.cucumber.BDDFrameworkType) PsiFile(com.intellij.psi.PsiFile) OptionalStepDefinitionExtensionPoint(org.jetbrains.plugins.cucumber.OptionalStepDefinitionExtensionPoint) Pair(com.intellij.openapi.util.Pair)

Example 4 with CucumberJvmExtensionPoint

use of org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint in project intellij-plugins by JetBrains.

the class CucumberStepReference method multiResolve.

@NotNull
@Override
public ResolveResult[] multiResolve(boolean incompleteCode) {
    final List<ResolveResult> result = new ArrayList<>();
    final List<PsiElement> resolvedElements = new ArrayList<>();
    final CucumberJvmExtensionPoint[] extensionList = Extensions.getExtensions(CucumberJvmExtensionPoint.EP_NAME);
    for (CucumberJvmExtensionPoint e : extensionList) {
        final List<PsiElement> extensionResult = e.resolveStep(myStep);
        for (final PsiElement element : extensionResult) {
            if (element != null && !resolvedElements.contains(element)) {
                resolvedElements.add(element);
                result.add(new ResolveResult() {

                    @Override
                    public PsiElement getElement() {
                        return element;
                    }

                    @Override
                    public boolean isValidResult() {
                        return true;
                    }
                });
            }
        }
    }
    return result.toArray(new ResolveResult[result.size()]);
}
Also used : ArrayList(java.util.ArrayList) CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) ResolveResult(com.intellij.psi.ResolveResult) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with CucumberJvmExtensionPoint

use of org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint in project intellij-plugins by JetBrains.

the class CucumberStepsIndex method isWritableStepLikeFile.

private boolean isWritableStepLikeFile(PsiElement child, PsiElement parent) {
    if (child instanceof PsiFile) {
        final PsiFile file = (PsiFile) child;
        CucumberJvmExtensionPoint ep = myExtensionMap.get(new BDDFrameworkType(file.getFileType()));
        return ep != null && ep.isWritableStepLikeFile(file, parent);
    }
    return false;
}
Also used : CucumberJvmExtensionPoint(org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint) PsiFile(com.intellij.psi.PsiFile) BDDFrameworkType(org.jetbrains.plugins.cucumber.BDDFrameworkType)

Aggregations

CucumberJvmExtensionPoint (org.jetbrains.plugins.cucumber.CucumberJvmExtensionPoint)5 PsiFile (com.intellij.psi.PsiFile)4 BDDFrameworkType (org.jetbrains.plugins.cucumber.BDDFrameworkType)3 NullableComputable (com.intellij.openapi.util.NullableComputable)1 Pair (com.intellij.openapi.util.Pair)1 PsiDirectory (com.intellij.psi.PsiDirectory)1 PsiElement (com.intellij.psi.PsiElement)1 PsiElementVisitor (com.intellij.psi.PsiElementVisitor)1 ResolveResult (com.intellij.psi.ResolveResult)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 OptionalStepDefinitionExtensionPoint (org.jetbrains.plugins.cucumber.OptionalStepDefinitionExtensionPoint)1 GherkinFile (org.jetbrains.plugins.cucumber.psi.GherkinFile)1