Skip to content

Commit

Permalink
[Java8] Replace ConstantPoolTypeInspector with typetools
Browse files Browse the repository at this point in the history
Related issues:
 - #937
  • Loading branch information
mpkorstanje committed Jul 9, 2017
1 parent cb20ce6 commit fcbd7ab
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 309 deletions.
10 changes: 0 additions & 10 deletions java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,6 @@
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>gherkin</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
Expand Down
35 changes: 10 additions & 25 deletions java/src/main/java/cucumber/runtime/java/JavaBackend.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package cucumber.runtime.java;

import static cucumber.runtime.io.MultiLoader.packageName;

import cucumber.api.java.After;
import cucumber.api.java.Before;
import cucumber.api.java.ObjectFactory;
import cucumber.api.java8.GlueBase;
import cucumber.api.java8.HookBody;
import cucumber.api.java8.HookNoArgsBody;
import cucumber.api.java8.StepdefBody;
import cucumber.runtime.Backend;
import cucumber.runtime.ClassFinder;
import cucumber.runtime.CucumberException;
import cucumber.runtime.DuplicateStepDefinitionException;
import cucumber.runtime.Env;
import cucumber.runtime.Glue;
import cucumber.runtime.HookDefinition;
import cucumber.runtime.StepDefinition;
import cucumber.runtime.UnreportedStepExecutor;
import cucumber.runtime.Utils;
import cucumber.runtime.io.MultiLoader;
Expand All @@ -30,8 +31,6 @@
import java.util.List;
import java.util.regex.Pattern;

import static cucumber.runtime.io.MultiLoader.packageName;

public class JavaBackend implements Backend {
public static final ThreadLocal<JavaBackend> INSTANCE = new ThreadLocal<JavaBackend>();
private final SnippetGenerator snippetGenerator = new SnippetGenerator(createSnippet());
Expand Down Expand Up @@ -157,14 +156,8 @@ void addStepDefinition(Annotation annotation, Method method) {
}
}

public void addStepDefinition(String regexp, long timeoutMillis, StepdefBody body, TypeIntrospector typeIntrospector) {
try {
glue.addStepDefinition(new Java8StepDefinition(Pattern.compile(regexp), timeoutMillis, body, typeIntrospector));
} catch (CucumberException e) {
throw e;
} catch (Exception e) {
throw new CucumberException(e);
}
public void addStepDefinition(StepDefinition stepDefinition) {
glue.addStepDefinition(stepDefinition);
}

void addHook(Annotation annotation, Method method) {
Expand All @@ -181,20 +174,12 @@ void addHook(Annotation annotation, Method method) {
}
}

public void addBeforeHookDefinition(String[] tagExpressions, long timeoutMillis, int order, HookBody body) {
glue.addBeforeHook(new Java8HookDefinition(tagExpressions, order, timeoutMillis, body));
}

public void addAfterHookDefinition(String[] tagExpressions, long timeoutMillis, int order, HookBody body) {
glue.addAfterHook(new Java8HookDefinition(tagExpressions, order, timeoutMillis, body));
}

public void addBeforeHookDefinition(String[] tagExpressions, long timeoutMillis, int order, HookNoArgsBody body) {
glue.addBeforeHook(new Java8HookDefinition(tagExpressions, order, timeoutMillis, body));
public void addBeforeHookDefinition(HookDefinition beforeHook) {
glue.addBeforeHook(beforeHook);
}

public void addAfterHookDefinition(String[] tagExpressions, long timeoutMillis, int order, HookNoArgsBody body) {
glue.addAfterHook(new Java8HookDefinition(tagExpressions, order, timeoutMillis, body));
public void addAfterHookDefinition(HookDefinition afterHook) {
glue.addAfterHook(afterHook);
}

private Pattern pattern(Annotation annotation) throws Throwable {
Expand Down

This file was deleted.

1 change: 0 additions & 1 deletion java/src/test/java/cucumber/runtime/java/JavaHookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import cucumber.runtime.Glue;
import cucumber.runtime.HookDefinition;
import cucumber.runtime.RuntimeGlue;
import cucumber.runtime.UndefinedStepsTracker;
import cucumber.runtime.xstream.LocalizedXStreams;
import gherkin.pickles.PickleLocation;
import gherkin.pickles.PickleTag;
Expand Down

This file was deleted.

This file was deleted.

6 changes: 5 additions & 1 deletion java8/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
</dependency>
<dependency>
<groupId>net.jodah</groupId>
<artifactId>typetools</artifactId>
</dependency>

<dependency>
<groupId>io.cucumber</groupId>
Expand Down Expand Up @@ -73,7 +77,7 @@ GherkinDialectProvider.DIALECTS.keySet().each { language ->
def dialect = dialectProvider.getDialect(language, null)
def normalized_language = dialect.language.replaceAll("[\\s-]", "_").toLowerCase()
if (!unsupported.contains(normalized_language)) {
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.java8.txt").getText()
def templateSource = new File(project.baseDir, "src${File.separator}main${File.separator}code_generator${File.separator}I18n.cucumber.runtime.java8.java8.txt").getText()
def className = "${normalized_language}".capitalize()
def binding = [ "i18n":dialect, "className":className ]
def template = engine.createTemplate(templateSource).make(binding)
Expand Down
21 changes: 15 additions & 6 deletions java8/src/main/code_generator/I18n.java8.txt
Original file line number Diff line number Diff line change
@@ -1,28 +1,37 @@
package cucumber.api.java8;

import cucumber.runtime.java8.ConstantPoolTypeIntrospector;
import cucumber.runtime.java8.LambdaGlueBase;
import cucumber.runtime.java.JavaBackend;
import cucumber.runtime.java8.Java8StepDefinition;
import cucumber.runtime.java8.LambdaGlueBase;

public interface ${className} extends LambdaGlueBase {
<% i18n.stepKeywords.findAll { !it.contains('*') && !it.matches("^\\d.*") }.sort().unique().each { kw -> %>
default void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A0 body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, 0, body, ConstantPoolTypeIntrospector.INSTANCE);
JavaBackend.INSTANCE.get().addStepDefinition(
new Java8StepDefinition(regexp, 0, StepdefBody.A0.class, body)
);
}

default void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A0 body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, timeoutMillis, body, ConstantPoolTypeIntrospector.INSTANCE);
JavaBackend.INSTANCE.get().addStepDefinition(
new Java8StepDefinition(regexp, timeoutMillis, StepdefBody.A0.class, body)
);
}
<% (1..9).each { arity ->
def ts = (1..arity).collect { n -> "T"+n }
def genericSignature = ts.join(",") %>

default <${genericSignature}> void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final StepdefBody.A${arity}<${genericSignature}> body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, 0, body, ConstantPoolTypeIntrospector.INSTANCE);
JavaBackend.INSTANCE.get().addStepDefinition(
new Java8StepDefinition(regexp, 0, StepdefBody.A${arity}.class, body)
);

}

default <${genericSignature}> void ${java.text.Normalizer.normalize(kw.replaceAll("[\\s',!]", ""), java.text.Normalizer.Form.NFC)}(final String regexp, final long timeoutMillis, final StepdefBody.A${arity}<${genericSignature}> body) {
JavaBackend.INSTANCE.get().addStepDefinition(regexp, timeoutMillis, body, ConstantPoolTypeIntrospector.INSTANCE);
JavaBackend.INSTANCE.get().addStepDefinition(
new Java8StepDefinition(regexp, timeoutMillis, StepdefBody.A${arity}.class, body)
);
}
<% } %>
<% } %>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package cucumber.runtime.java;
package cucumber.runtime.java8;

import static java.util.Arrays.asList;

import cucumber.api.Scenario;
import cucumber.api.java8.HookBody;
import cucumber.api.java8.HookNoArgsBody;
import cucumber.runtime.HookDefinition;
import cucumber.runtime.Timeout;
import cucumber.runtime.TagPredicate;
import cucumber.runtime.Timeout;
import gherkin.pickles.PickleTag;

import java.util.Collection;

import static java.util.Arrays.asList;

public class Java8HookDefinition implements HookDefinition {
private final TagPredicate tagPredicate;
private final int order;
Expand Down
Loading

0 comments on commit fcbd7ab

Please sign in to comment.