diff --git a/examples/java-datatable/src/main/java/cucumber/examples/datatable/AnimalValidator.java b/examples/java-datatable/src/main/java/cucumber/examples/datatable/AnimalValidator.java
new file mode 100644
index 00000000..acb2fb9a
--- /dev/null
+++ b/examples/java-datatable/src/main/java/cucumber/examples/datatable/AnimalValidator.java
@@ -0,0 +1,78 @@
+package cucumber.examples.datatable;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+import io.cucumber.core.gherkin.DataTableArgument;
+import io.cucumber.plugin.ConcurrentEventListener;
+import io.cucumber.plugin.Plugin;
+import io.cucumber.plugin.event.EventPublisher;
+import io.cucumber.plugin.event.PickleStepTestStep;
+import io.cucumber.plugin.event.Step;
+import io.cucumber.plugin.event.StepArgument;
+import io.cucumber.plugin.event.TestStep;
+import io.cucumber.plugin.event.TestStepFinished;
+
+/**
+ * This validator is enabled in the feature by using
+ * #validation-plugin: cucumber.examples.datatable.AnimalValidator
+ */
+public class AnimalValidator implements Plugin, ConcurrentEventListener {
+
+ private ConcurrentHashMap errors = new ConcurrentHashMap<>();
+
+ @Override
+ public void setEventPublisher(EventPublisher publisher) {
+ publisher.registerHandlerFor(TestStepFinished.class, this::handleTestStepFinished);
+ }
+
+ private void handleTestStepFinished(TestStepFinished event) {
+ TestStep testStep = event.getTestStep();
+ if (testStep instanceof PickleStepTestStep) {
+ PickleStepTestStep pickleStepTestStep = (PickleStepTestStep) testStep;
+ Step step = pickleStepTestStep.getStep();
+ if ("the animal {string}".equals(pickleStepTestStep.getPattern())) {
+ StepArgument argument = step.getArgument();
+ Animals animal = loadAnimal(pickleStepTestStep.getDefinitionArgument().get(0).getValue());
+ if (animal == null) {
+ // Invalid animal!
+ return;
+ }
+ if (argument instanceof DataTableArgument dataTable) {
+ List availableData = animal.getAvailableData();
+ List> cells = dataTable.cells();
+ for (int i = 1; i < cells.size(); i++) {
+ int line = dataTable.getLine() + i;
+ List list = cells.get(i);
+ String vv = list.get(0);
+ if (!animal.getAvailableDataForAnimals().contains(vv)) {
+ errors.put(line, vv + " is not valid for any animal");
+ } else if (!availableData.contains(vv)) {
+ errors.put(line, vv + " is not valid for animal " + animal.getClass().getSimpleName());
+ }
+ }
+ }
+ }
+ }
+ }
+ //This is a magic method called by cucumber-eclipse to fetch the final errors and display them in the document
+ public Map getValidationErrors() {
+ return errors;
+ }
+
+ private Animals loadAnimal(String value) {
+ try {
+ Class> clz = getClass().getClassLoader()
+ .loadClass("cucumber.examples.datatable." + value.replace("\"", ""));
+ Object instance = clz.getConstructor().newInstance();
+ if (instance instanceof Animals anml) {
+ return anml;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ return null;
+ }
+
+}
diff --git a/examples/java-datatable/src/test/resources/cucumber/examples/datatable.feature b/examples/java-datatable/src/test/resources/cucumber/examples/datatable.feature
index f1205aff..e6133f47 100644
--- a/examples/java-datatable/src/test/resources/cucumber/examples/datatable.feature
+++ b/examples/java-datatable/src/test/resources/cucumber/examples/datatable.feature
@@ -1,7 +1,8 @@
#language: en
+#This comment below enables the validation plugin
+#validation-plugin: cucumber.examples.datatable.AnimalValidator
Feature: Connection between DataTable Key and a specific Step Value
-
Scenario: All Keys are related to a Step Value. Example 1
Given the animal "Cat"
| Key | Value |
@@ -10,8 +11,7 @@ Feature: Connection between DataTable Key and a specific Step Value
| Whiskers | 24 |
Then the food is "fish"
-
-
+
Scenario: All Keys are related to a Step Value. Example 2
Given the animal "Elephant"
| Key | Value |
@@ -21,8 +21,7 @@ Feature: Connection between DataTable Key and a specific Step Value
| Tusk | 1.3 |
Then the food is "leaves"
-
-
+
Scenario: There are some unrelated Keys to a Step Value. This Keys are available for other Step Value
Given the animal "Cat"
| Key | Value |
@@ -42,5 +41,6 @@ Feature: Connection between DataTable Key and a specific Step Value
| Whiskers | 24 |
| Wings | 2 |
- Then the food is "fish"
-
+ Then the food isa "fish"
+
+ ### ffeeecc
\ No newline at end of file
diff --git a/io.cucumber.eclipse.editor/plugin.xml b/io.cucumber.eclipse.editor/plugin.xml
index 5598bb71..cb437a59 100644
--- a/io.cucumber.eclipse.editor/plugin.xml
+++ b/io.cucumber.eclipse.editor/plugin.xml
@@ -110,6 +110,14 @@
+
+
+
+
+ errors, boolean persistent) {
+ if (errors == null || errors.isEmpty()) {
+ return;
+ }
+
+ mark(stepDefinitionResource, new IMarkerBuilder() {
+ @Override
+ public void build() throws CoreException {
+ Map