package org.jbehave.scenario.steps;

import java.lang.reflect.Method;
import java.util.ArrayList;

import org.jbehave.scenario.annotations.Given;
import org.jbehave.scenario.annotations.Then;
import org.jbehave.scenario.annotations.When;

public class Steps {
	
	private final StepPatternBuilder patternBuilder;
	
	public Steps() {
		this(new DollarStepPatternBuilder());
	}

	public Steps(StepPatternBuilder patternConverter) {
		this.patternBuilder = patternConverter;
	}

	/**
	 * Returns all the steps that can be performed by this class.
	 */
	public CandidateStep[] getSteps() {
		ArrayList<CandidateStep> steps = new ArrayList<CandidateStep>();
		for (Method method : this.getClass().getMethods()) {
			if (method.isAnnotationPresent(Given.class)) {
				steps.add(given(method.getAnnotation(Given.class).value(), method));
			}
			if (method.isAnnotationPresent(When.class)) {
				steps.add(when(method.getAnnotation(When.class).value(), method));
			}
			if (method.isAnnotationPresent(Then.class)) {
				steps.add(then(method.getAnnotation(Then.class).value(), method));
			}
		}
		return steps.toArray(new CandidateStep[steps.size()]);
	}
	
	private org.jbehave.scenario.steps.Given given(String value, Method method) {
		return new org.jbehave.scenario.steps.Given(value, method, this, patternBuilder);
	}
	private org.jbehave.scenario.steps.When when(String value, Method method) {
		return new org.jbehave.scenario.steps.When(value, method, this, patternBuilder);
	}
	private org.jbehave.scenario.steps.Then then(String value, Method method) {
		return new org.jbehave.scenario.steps.Then(value, method, this, patternBuilder);
	}
}

@@ -96,148 +96,8 @@
 t;%0A%0A
-import org.jbehave.scenario.annotations.Given;%0Aimport org.jbehave.scenario.annotations.Then;%0Aimport org.jbehave.scenario.annotations.When;%0A%0A
 publ
@@ -594,16 +594,49 @@
 Present(
+org.jbehave.scenario.annotations.
 Given.cl
@@ -684,16 +684,49 @@
 otation(
+org.jbehave.scenario.annotations.
 Given.cl
@@ -788,16 +788,49 @@
 Present(
+org.jbehave.scenario.annotations.
 When.cla
@@ -876,16 +876,49 @@
 otation(
+org.jbehave.scenario.annotations.
 When.cla
@@ -979,16 +979,49 @@
 Present(
+org.jbehave.scenario.annotations.
 Then.cla
@@ -1067,16 +1067,49 @@
 otation(
+org.jbehave.scenario.annotations.
 Then.cla
@@ -1215,35 +1215,8 @@
 ate 
-org.jbehave.scenario.steps.
 Give
@@ -1271,35 +1271,8 @@
 new 
-org.jbehave.scenario.steps.
 Give
@@ -1327,35 +1327,8 @@
 ate 
-org.jbehave.scenario.steps.
 When
@@ -1381,35 +1381,8 @@
 new 
-org.jbehave.scenario.steps.
 When
@@ -1436,35 +1436,8 @@
 ate 
-org.jbehave.scenario.steps.
 Then
@@ -1490,35 +1490,8 @@
 new 
-org.jbehave.scenario.steps.
 Then

Use FQCN for annotations rather than steps.