Skip to content

Commit

Permalink
[Java8] Add error when types could not be resolved on Java 12+
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Feb 27, 2020
1 parent 0386fe7 commit e1fd6f5
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
15 changes: 15 additions & 0 deletions java8/src/main/java/io/cucumber/java8/AbstractGlueDefinition.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.cucumber.java8;

import io.cucumber.core.backend.ScenarioScoped;
import net.jodah.typetools.TypeResolver;

import java.lang.reflect.Method;
import java.util.ArrayList;
Expand Down Expand Up @@ -42,4 +43,18 @@ private Method getAcceptMethod(Class<?> bodyClass) {
}
return acceptMethods.get(0);
}

Class<?>[] resolveRawArguments(Class<?> bodyClass, Class<?> body) {
Class<?>[] rawArguments = TypeResolver.resolveRawArguments(bodyClass, body);
for (Class<?> aClass : rawArguments) {
if (TypeResolver.Unknown.class.equals(aClass)) {
throw new IllegalStateException("" +
"Could resolve the return type of the lambda at " + location.getFileName() + ":" + location.getLineNumber() + "\n" +
"This version of cucumber-java8 is not compatible with Java 12+\n" +
"See: https://github.com/cucumber/cucumber-jvm/issues/1817"
);
}
}
return rawArguments;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

import io.cucumber.core.backend.DataTableTypeDefinition;
import io.cucumber.datatable.DataTableType;
import net.jodah.typetools.TypeResolver;

final class Java8DataTableCellDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;

Java8DataTableCellDefinition(String[] emptyPatterns, DataTableCellDefinitionBody<?> body) {
super(body, new Exception().getStackTrace()[3], emptyPatterns);
Class<?> returnType = TypeResolver.resolveRawArguments(DataTableCellDefinitionBody.class, body.getClass())[0];
Class<?> returnType = resolveRawArguments(DataTableCellDefinitionBody.class, body.getClass())[0];
this.dataTableType = new DataTableType(
returnType,
(String cell) -> execute(replaceEmptyPatternsWithEmptyString(cell))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import io.cucumber.datatable.DataTable;
import io.cucumber.datatable.DataTableType;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.Map;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableEntryDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.List;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DataTableRowDefinition extends AbstractDatatableElementTransformerDefinition implements DataTableTypeDefinition {

private final DataTableType dataTableType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import io.cucumber.core.exception.CucumberException;
import io.cucumber.docstring.DocStringType;

import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8DocStringTypeDefinition extends AbstractGlueDefinition implements DocStringTypeDefinition {

private final DocStringType docStringType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static net.jodah.typetools.TypeResolver.resolveRawArguments;

final class Java8StepDefinition extends AbstractGlueDefinition implements StepDefinition {

Expand Down
3 changes: 0 additions & 3 deletions java8/src/main/java/io/cucumber/java8/LambdaTypeResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ public Type resolve() {
}

public Type getType() {
if (net.jodah.typetools.TypeResolver.Unknown.class.equals(type)) {
return Object.class;
}
return type;
}

Expand Down

0 comments on commit e1fd6f5

Please sign in to comment.