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;
}
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;
}
Aggregations