AbstractCandidateSteps.java

  1. package org.jbehave.core.steps;

  2. import java.lang.reflect.Method;
  3. import java.util.List;

  4. import org.jbehave.core.configuration.Configuration;
  5. import org.jbehave.core.parsers.StepMatcher;
  6. import org.jbehave.core.parsers.StepPatternParser;

  7. public abstract class AbstractCandidateSteps implements CandidateSteps {
  8.     private final Configuration configuration;

  9.     protected AbstractCandidateSteps(Configuration configuration) {
  10.         this.configuration = configuration;
  11.     }

  12.     protected Configuration configuration() {
  13.         return configuration;
  14.     }

  15.     protected void addCandidatesFromVariants(List<StepCandidate> candidates, Method method, StepType stepType,
  16.             String value, int priority, Class<?> type, InjectableStepsFactory stepsFactory, String[] steps) {
  17.         StepPatternParser stepPatternParser = configuration.stepPatternParser();
  18.         PatternVariantBuilder patternVariantBuilder = new PatternVariantBuilder(value);
  19.         for (String variant : patternVariantBuilder.allVariants()) {
  20.             StepMatcher stepMatcher = stepPatternParser.parseStep(stepType, variant);
  21.             StepCreator stepCreator = createStepCreator(type, stepsFactory, stepMatcher);
  22.             stepCreator.useParanamer(configuration.paranamer());
  23.             StepCandidate candidate = new StepCandidate(variant, priority, stepType, method, type, stepsFactory,
  24.                     configuration.keywords(), stepMatcher, stepPatternParser.getPrefix(), stepCreator, steps,
  25.                     configuration.stepMonitor());
  26.             candidates.add(candidate);
  27.         }
  28.     }

  29.     protected final StepCreator createStepCreator(Class<?> type, InjectableStepsFactory stepsFactory) {
  30.         return createStepCreator(type, stepsFactory, null);
  31.     }

  32.     private StepCreator createStepCreator(Class<?> type, InjectableStepsFactory stepsFactory, StepMatcher stepMatcher) {
  33.         return new StepCreator(type, stepsFactory, configuration.stepsContext(), configuration.parameterConverters(),
  34.                 configuration.expressionResolver(), configuration.parameterControls(), stepMatcher,
  35.                 configuration.stepMonitor(), configuration.storyControls().dryRun());
  36.     }
  37. }