io.cucumber.cucumberexpressions.PatternCompilerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of cucumber-expressions Show documentation
Show all versions of cucumber-expressions Show documentation
Cucumber Expressions are simple patterns for matching Step Definitions with Gherkin steps
package io.cucumber.cucumberexpressions;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;
final class PatternCompilerProvider {
// visible from tests
static PatternCompiler service;
private PatternCompilerProvider() {
}
static synchronized PatternCompiler getCompiler() {
if (service == null) {
ServiceLoader loader = ServiceLoader.load(PatternCompiler.class);
Iterator iterator = loader.iterator();
findPatternCompiler(iterator);
}
return service;
}
static void findPatternCompiler(Iterator iterator) {
if (iterator.hasNext()) {
service = iterator.next();
if (iterator.hasNext()) {
throwMoreThanOneCompilerException(iterator);
}
} else {
service = new DefaultPatternCompiler();
}
}
private static void throwMoreThanOneCompilerException(Iterator iterator) {
List> allCompilers = new ArrayList<>();
allCompilers.add(service.getClass());
while (iterator.hasNext()) {
allCompilers.add(iterator.next().getClass());
}
throw new IllegalStateException("More than one PatternCompiler: " + allCompilers);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy