-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Java8] Replace ConstantPoolTypeIntrospector #1178
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
package cucumber.runtime.java; | ||
|
||
import static cucumber.runtime.io.MultiLoader.packageName; | ||
import static cucumber.runtime.java.ObjectFactoryLoader.loadObjectFactory; | ||
import static java.lang.Thread.currentThread; | ||
|
||
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; | ||
|
@@ -30,14 +33,12 @@ | |
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()); | ||
|
||
private Snippet createSnippet() { | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
ClassLoader classLoader = currentThread().getContextClassLoader(); | ||
try { | ||
classLoader.loadClass("cucumber.runtime.java8.LambdaGlueBase"); | ||
return new Java8Snippet(); | ||
|
@@ -59,24 +60,17 @@ private Snippet createSnippet() { | |
* @param resourceLoader | ||
*/ | ||
public JavaBackend(ResourceLoader resourceLoader) { | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); | ||
methodScanner = new MethodScanner(classFinder); | ||
objectFactory = ObjectFactoryLoader.loadObjectFactory(classFinder, Env.INSTANCE.get(ObjectFactory.class.getName())); | ||
this(new ResourceLoaderClassFinder(resourceLoader, currentThread().getContextClassLoader())); | ||
} | ||
|
||
public JavaBackend(ObjectFactory objectFactory) { | ||
ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); | ||
ResourceLoader resourceLoader = new MultiLoader(classLoader); | ||
classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader); | ||
methodScanner = new MethodScanner(classFinder); | ||
this.objectFactory = objectFactory; | ||
private JavaBackend(ClassFinder classFinder) { | ||
this(loadObjectFactory(classFinder, Env.INSTANCE.get(ObjectFactory.class.getName())), classFinder); | ||
} | ||
|
||
public JavaBackend(ObjectFactory objectFactory, ClassFinder classFinder) { | ||
this.objectFactory = objectFactory; | ||
this.classFinder = classFinder; | ||
methodScanner = new MethodScanner(classFinder); | ||
this.objectFactory = objectFactory; | ||
this.methodScanner = new MethodScanner(classFinder); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Rewrote the constructors to be idiomatic java. |
||
} | ||
|
||
@Override | ||
|
@@ -157,44 +151,30 @@ 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)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has moved into the generated code. |
||
} 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) { | ||
if (objectFactory.addClass(method.getDeclaringClass())) { | ||
if (annotation.annotationType().equals(Before.class)) { | ||
String[] tagExpressions = ((Before) annotation).value(); | ||
long timeout = ((Before) annotation).timeout(); | ||
glue.addBeforeHook(new JavaHookDefinition(method, tagExpressions, ((Before) annotation).order(), timeout, objectFactory)); | ||
addBeforeHookDefinition(new JavaHookDefinition(method, tagExpressions, ((Before) annotation).order(), timeout, objectFactory)); | ||
} else { | ||
String[] tagExpressions = ((After) annotation).value(); | ||
long timeout = ((After) annotation).timeout(); | ||
glue.addAfterHook(new JavaHookDefinition(method, tagExpressions, ((After) annotation).order(), timeout, objectFactory)); | ||
addAfterHookDefinition(new JavaHookDefinition(method, tagExpressions, ((After) annotation).order(), timeout, objectFactory)); | ||
} | ||
} | ||
} | ||
|
||
public void addBeforeHookDefinition(String[] tagExpressions, long timeoutMillis, int order, HookBody body) { | ||
glue.addBeforeHook(new Java8HookDefinition(tagExpressions, order, timeoutMillis, body)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has moved into the generated code. |
||
} | ||
|
||
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 { | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both are transitive dependencies through cucumber-core.