Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt

### Fixed
- [cpp] Actually use the VERSION file ([#376](https://github.com/cucumber/gherkin/pull/376))
- [Java] Prefer the longest step keyword ([#401](https://github.com/cucumber/gherkin/pull/401))

## [32.1.1] - 2025-04-11
### Fixed
Expand Down
8 changes: 7 additions & 1 deletion java/src/main/java/io/cucumber/gherkin/GherkinDialect.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import io.cucumber.messages.types.StepKeywordType;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -82,7 +84,11 @@ private static List<String> distinctKeywords(List<String>... keywords) {
for (List<String> keyword : keywords) {
uniqueKeywords.addAll(keyword);
}
return unmodifiableList(new ArrayList<>(uniqueKeywords));
List<String> sortedKeywords = new ArrayList<>(uniqueKeywords);
// Sort from longest to shortest
Comparator<String> naturalOrder = Comparator.naturalOrder();
Collections.sort(sortedKeywords, naturalOrder.reversed());
return unmodifiableList(sortedKeywords);
}

private static Map<String, Set<StepKeywordType>> aggregateKeywordTypes(
Expand Down