From fa9577ef550f9cc4f0c5d062be094e051f03a284 Mon Sep 17 00:00:00 2001 From: qvdk Date: Wed, 11 Mar 2020 15:12:04 +0100 Subject: [PATCH] fix #391 - step definition using annotations from io.cucumber are not detected --- .../steps/jdt/JavaStepDefinitionsProvider.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/cucumber.eclipse.steps.jdt/src/main/java/cucumber/eclipse/steps/jdt/JavaStepDefinitionsProvider.java b/cucumber.eclipse.steps.jdt/src/main/java/cucumber/eclipse/steps/jdt/JavaStepDefinitionsProvider.java index c2b01501..2f2a3b56 100644 --- a/cucumber.eclipse.steps.jdt/src/main/java/cucumber/eclipse/steps/jdt/JavaStepDefinitionsProvider.java +++ b/cucumber.eclipse.steps.jdt/src/main/java/cucumber/eclipse/steps/jdt/JavaStepDefinitionsProvider.java @@ -100,7 +100,7 @@ private List getCukeSteps(ICompilationUnit iCompUnit, MarkerFact if (m.find()) { if ("*".equals(m.group(2))) { importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(), - CUCUMBER_API_JAVA + m.group(1), m.group(1))); + CUCUMBER_API_JAVA + m.group(1), m.group(1), progressMonitor)); } else { importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1))); } @@ -111,7 +111,7 @@ private List getCukeSteps(ICompilationUnit iCompUnit, MarkerFact if (m.find()) { if ("*".equals(m.group(2))) { importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(), - IO_CUCUMBER_JAVA + m.group(1), m.group(1))); + IO_CUCUMBER_JAVA + m.group(1), m.group(1), progressMonitor)); } else { importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1))); } @@ -260,7 +260,7 @@ private int getLineNumber(ICompilationUnit compUnit, IAnnotation annotation) thr } private List getAllAnnotationsInPackage(final IJavaProject javaProject, - final String packageFrag, final String lang) throws CoreException, JavaModelException { + final String packageFrag, final String lang, IProgressMonitor monitor) throws CoreException, JavaModelException { SearchPattern pattern = SearchPattern.createPattern(packageFrag, IJavaSearchConstants.PACKAGE, IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); @@ -287,12 +287,12 @@ public void acceptSearchMatch(SearchMatch match) { } }; SearchEngine engine = new SearchEngine(); - jdtSearch(engine, pattern, scope, requestor); + jdtSearch(engine, pattern, scope, requestor, monitor); return annotations; } private void jdtSearch(SearchEngine engine, SearchPattern pattern, IJavaSearchScope scope, - SearchRequestor requestor) throws CoreException { + SearchRequestor requestor, IProgressMonitor monitor) throws CoreException { try { engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope, requestor, null); @@ -315,6 +315,10 @@ private CucumberAnnotation getCukeAnnotation(List importedAn if (m.find()) { return new CucumberAnnotation(m.group(2), m.group(1)); } + m = ioCucumberAnnotationMatcher.matcher(annotation.getElementName()); + if (m.find()) { + return new CucumberAnnotation(m.group(2), m.group(1)); + } for (CucumberAnnotation cuke : importedAnnotations) { if (cuke.getAnnotation().equals(annotation.getElementName())) return cuke; @@ -397,7 +401,7 @@ public boolean support(IResource resource) throws CoreException { private Set findStepDefinitionsInClasspath(IJavaProject javaProject, MarkerFactory markerFactory, IProgressMonitor monitor) throws CoreException { - SearchPattern searchPattern = SearchPattern.createPattern("cucumber.api.java.*.*", IJavaSearchConstants.TYPE, + SearchPattern searchPattern = SearchPattern.createPattern("*cucumber*.java*", IJavaSearchConstants.TYPE, IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE); @@ -456,7 +460,7 @@ public void acceptSearchMatch(SearchMatch match) { }; for (IJavaSearchScope scope : scopes) { - jdtSearch(engine, searchPattern, scope, requestor); + jdtSearch(engine, searchPattern, scope, requestor, monitor); } return stepDefinitions;