Search in sources :

Example 1 with JavaStepDefinition

use of org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition 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;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiMethod(com.intellij.psi.PsiMethod) PsiClass(com.intellij.psi.PsiClass) ArrayList(java.util.ArrayList) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) JavaStepDefinition(org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition)

Example 2 with JavaStepDefinition

use of org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition in project intellij-plugins by JetBrains.

the class CucumberJava8Extension method loadStepsFor.

@Override
public List<AbstractStepDefinition> loadStepsFor(@Nullable PsiFile featureFile, @NotNull Module module) {
    final List<AbstractStepDefinition> result = new ArrayList<>();
    final GlobalSearchScope dependenciesScope = module.getModuleWithDependenciesAndLibrariesScope(true);
    final GlobalSearchScope javaFiles = GlobalSearchScope.getScopeRestrictedByFileTypes(dependenciesScope, JavaFileType.INSTANCE);
    String[] keywords = new String[] { "Given", "And", "Then", "But", "When" };
    for (String method : keywords) {
        PsiSearchHelper.SERVICE.getInstance(module.getProject()).processElementsWithWord((element, offsetInElement) -> {
            final PsiElement parent = element.getParent();
            if (parent != null) {
                final PsiReference[] references = parent.getReferences();
                for (PsiReference ref : references) {
                    PsiElement resolved = ref.resolve();
                    PsiClass psiClass = PsiTreeUtil.getParentOfType(resolved, PsiClass.class);
                    if (psiClass != null) {
                        final String fqn = psiClass.getQualifiedName();
                        if (fqn != null && fqn.startsWith("cucumber.api.java8")) {
                            final PsiMethodCallExpression methodCallExpression = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
                            result.add(new JavaStepDefinition(methodCallExpression));
                        }
                    }
                }
            }
            return true;
        }, javaFiles, method, UsageSearchContext.IN_CODE, true);
    }
    return result;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ArrayList(java.util.ArrayList) AbstractStepDefinition(org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition) JavaStepDefinition(org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition)

Aggregations

GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 ArrayList (java.util.ArrayList)2 JavaStepDefinition (org.jetbrains.plugins.cucumber.java.steps.JavaStepDefinition)2 AbstractStepDefinition (org.jetbrains.plugins.cucumber.steps.AbstractStepDefinition)2 PsiClass (com.intellij.psi.PsiClass)1 PsiMethod (com.intellij.psi.PsiMethod)1