Skip to content

Commit 05d723a

Browse files
authored
Merge pull request #392 from cucumber/fix/missing_stepdef_from_classpath_with_annot_iocucumber
fix #391 - step definition using annotations from io.cucumber are not detected
2 parents 6149c9c + fa9577e commit 05d723a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

cucumber.eclipse.steps.jdt/src/main/java/cucumber/eclipse/steps/jdt/JavaStepDefinitionsProvider.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private List<StepDefinition> getCukeSteps(ICompilationUnit iCompUnit, MarkerFact
100100
if (m.find()) {
101101
if ("*".equals(m.group(2))) {
102102
importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(),
103-
CUCUMBER_API_JAVA + m.group(1), m.group(1)));
103+
CUCUMBER_API_JAVA + m.group(1), m.group(1), progressMonitor));
104104
} else {
105105
importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1)));
106106
}
@@ -111,7 +111,7 @@ private List<StepDefinition> getCukeSteps(ICompilationUnit iCompUnit, MarkerFact
111111
if (m.find()) {
112112
if ("*".equals(m.group(2))) {
113113
importedAnnotations.addAll(getAllAnnotationsInPackage(iCompUnit.getJavaProject(),
114-
IO_CUCUMBER_JAVA + m.group(1), m.group(1)));
114+
IO_CUCUMBER_JAVA + m.group(1), m.group(1), progressMonitor));
115115
} else {
116116
importedAnnotations.add(new CucumberAnnotation(m.group(2), m.group(1)));
117117
}
@@ -260,7 +260,7 @@ private int getLineNumber(ICompilationUnit compUnit, IAnnotation annotation) thr
260260
}
261261

262262
private List<CucumberAnnotation> getAllAnnotationsInPackage(final IJavaProject javaProject,
263-
final String packageFrag, final String lang) throws CoreException, JavaModelException {
263+
final String packageFrag, final String lang, IProgressMonitor monitor) throws CoreException, JavaModelException {
264264

265265
SearchPattern pattern = SearchPattern.createPattern(packageFrag, IJavaSearchConstants.PACKAGE,
266266
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
@@ -287,12 +287,12 @@ public void acceptSearchMatch(SearchMatch match) {
287287
}
288288
};
289289
SearchEngine engine = new SearchEngine();
290-
jdtSearch(engine, pattern, scope, requestor);
290+
jdtSearch(engine, pattern, scope, requestor, monitor);
291291
return annotations;
292292
}
293293

294294
private void jdtSearch(SearchEngine engine, SearchPattern pattern, IJavaSearchScope scope,
295-
SearchRequestor requestor) throws CoreException {
295+
SearchRequestor requestor, IProgressMonitor monitor) throws CoreException {
296296
try {
297297
engine.search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, scope,
298298
requestor, null);
@@ -315,6 +315,10 @@ private CucumberAnnotation getCukeAnnotation(List<CucumberAnnotation> importedAn
315315
if (m.find()) {
316316
return new CucumberAnnotation(m.group(2), m.group(1));
317317
}
318+
m = ioCucumberAnnotationMatcher.matcher(annotation.getElementName());
319+
if (m.find()) {
320+
return new CucumberAnnotation(m.group(2), m.group(1));
321+
}
318322
for (CucumberAnnotation cuke : importedAnnotations) {
319323
if (cuke.getAnnotation().equals(annotation.getElementName()))
320324
return cuke;
@@ -397,7 +401,7 @@ public boolean support(IResource resource) throws CoreException {
397401
private Set<StepDefinition> findStepDefinitionsInClasspath(IJavaProject javaProject, MarkerFactory markerFactory,
398402
IProgressMonitor monitor) throws CoreException {
399403

400-
SearchPattern searchPattern = SearchPattern.createPattern("cucumber.api.java.*.*", IJavaSearchConstants.TYPE,
404+
SearchPattern searchPattern = SearchPattern.createPattern("*cucumber*.java*", IJavaSearchConstants.TYPE,
401405
IJavaSearchConstants.IMPORT_DECLARATION_TYPE_REFERENCE,
402406
SearchPattern.R_PATTERN_MATCH | SearchPattern.R_CASE_SENSITIVE);
403407

@@ -456,7 +460,7 @@ public void acceptSearchMatch(SearchMatch match) {
456460
};
457461

458462
for (IJavaSearchScope scope : scopes) {
459-
jdtSearch(engine, searchPattern, scope, requestor);
463+
jdtSearch(engine, searchPattern, scope, requestor, monitor);
460464
}
461465

462466
return stepDefinitions;

0 commit comments

Comments
 (0)