Skip to content
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

Proposed Fix for issue #668 - convert Gherkin table to List<T> in Scala DSL #669

Merged
merged 2 commits into from
Mar 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scala/gen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ for (i <- 1 to 22) {
val f = "(" + ts + ") => Any"
val p1 = "def apply[" + ts + "](f: " + f + ")"
val p2 = "(implicit " + (1 to i).map(n => "m" + n + ":Manifest[T" + n + "]").mkString(", ") + ")"
val register = "\n register(List(" + (1 to i).map("m" +).mkString(", ") + ")) {\n"
val register = "\n register(functionParams(f)) {\n"
val pf = " case List(" + (1 to i).map("a" + _ + ":AnyRef").mkString(", ") + ") => \n f(" + (1 to i).map(n => "a" + n + ".asInstanceOf[T" + n + "]").mkString(",\n ") + ")"
val closeRegister = "\n }\n}"

Expand Down
54 changes: 28 additions & 26 deletions scala/src/main/scala/cucumber/api/scala/ScalaDsl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import _root_.cucumber.runtime.scala.ScalaStepDefinition
import _root_.cucumber.runtime.HookDefinition
import _root_.cucumber.runtime.StepDefinition
import collection.mutable.ArrayBuffer
import java.lang.reflect.Type

/**
* Base trait for a scala step definition implementation.
Expand Down Expand Up @@ -57,7 +58,7 @@ trait ScalaDsl { self =>
def apply(f: => Unit){ apply(f _) }

def apply(fun: Fun0) {
register(Nil) {case Nil => fun.f()}
register(Array[Type]()) {case Nil => fun.f()}
}

/**
Expand Down Expand Up @@ -91,22 +92,22 @@ trait ScalaDsl { self =>
*/

def apply[T1](f: (T1) => Any)(implicit m1:Manifest[T1]) {
register(List(m1)) {
register(functionParams(f)) {
case List(a1:AnyRef) =>
f(a1.asInstanceOf[T1])
}
}

def apply[T1, T2](f: (T1, T2) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2]) {
register(List(m1, m2)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2])
}
}

def apply[T1, T2, T3](f: (T1, T2, T3) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3]) {
register(List(m1, m2, m3)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -115,7 +116,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4](f: (T1, T2, T3, T4) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4]) {
register(List(m1, m2, m3, m4)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -125,7 +126,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5](f: (T1, T2, T3, T4, T5) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5]) {
register(List(m1, m2, m3, m4, m5)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -136,7 +137,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6](f: (T1, T2, T3, T4, T5, T6) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6]) {
register(List(m1, m2, m3, m4, m5, m6)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -148,7 +149,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7](f: (T1, T2, T3, T4, T5, T6, T7) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7]) {
register(List(m1, m2, m3, m4, m5, m6, m7)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -161,7 +162,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8](f: (T1, T2, T3, T4, T5, T6, T7, T8) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -175,7 +176,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -190,7 +191,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -206,7 +207,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -223,7 +224,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -241,7 +242,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -260,7 +261,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -280,7 +281,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -301,7 +302,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -323,7 +324,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -346,7 +347,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17], m18:Manifest[T18]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -370,7 +371,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17], m18:Manifest[T18], m19:Manifest[T19]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -395,7 +396,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17], m18:Manifest[T18], m19:Manifest[T19], m20:Manifest[T20]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -421,7 +422,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17], m18:Manifest[T18], m19:Manifest[T19], m20:Manifest[T20], m21:Manifest[T21]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -448,7 +449,7 @@ trait ScalaDsl { self =>
}

def apply[T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22](f: (T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21, T22) => Any)(implicit m1:Manifest[T1], m2:Manifest[T2], m3:Manifest[T3], m4:Manifest[T4], m5:Manifest[T5], m6:Manifest[T6], m7:Manifest[T7], m8:Manifest[T8], m9:Manifest[T9], m10:Manifest[T10], m11:Manifest[T11], m12:Manifest[T12], m13:Manifest[T13], m14:Manifest[T14], m15:Manifest[T15], m16:Manifest[T16], m17:Manifest[T17], m18:Manifest[T18], m19:Manifest[T19], m20:Manifest[T20], m21:Manifest[T21], m22:Manifest[T22]) {
register(List(m1, m2, m3, m4, m5, m6, m7, m8, m9, m10, m11, m12, m13, m14, m15, m16, m17, m18, m19, m20, m21, m22)) {
register(functionParams(f)) {
case List(a1:AnyRef, a2:AnyRef, a3:AnyRef, a4:AnyRef, a5:AnyRef, a6:AnyRef, a7:AnyRef, a8:AnyRef, a9:AnyRef, a10:AnyRef, a11:AnyRef, a12:AnyRef, a13:AnyRef, a14:AnyRef, a15:AnyRef, a16:AnyRef, a17:AnyRef, a18:AnyRef, a19:AnyRef, a20:AnyRef, a21:AnyRef, a22:AnyRef) =>
f(a1.asInstanceOf[T1],
a2.asInstanceOf[T2],
Expand All @@ -475,9 +476,9 @@ trait ScalaDsl { self =>
}
}

private def register(manifests: List[Manifest[_]])(pf: PartialFunction[List[Any], Any]){
private def register(types: Array[Type])(pf: PartialFunction[List[Any], Any]) = {
val frame: StackTraceElement = obtainFrame
stepDefinitions += new ScalaStepDefinition(frame, name, regex, manifests.map(_.erasure), pf)
stepDefinitions += new ScalaStepDefinition(frame, name, regex, types, pf)
}

/**
Expand All @@ -490,6 +491,7 @@ trait ScalaDsl { self =>
frames.find(_.getClassName == currentClass).get
}

private def functionParams(f: Any) =
f.getClass.getDeclaredMethods.filterNot(_.isBridge).head.getGenericParameterTypes
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import cucumber.api.Transform
class ScalaStepDefinition(frame:StackTraceElement,
name:String,
pattern:String,
parameterInfos:List[Class[_]],
parameterInfos:Array[Type],
f:List[Any] => Any) extends StepDefinition {

/**
Expand All @@ -53,15 +53,15 @@ class ScalaStepDefinition(frame:StackTraceElement,
/**
* How many declared parameters this stepdefinition has. Returns null if unknown.
*/
def getParameterCount() = parameterInfos.size()
def getParameterCount() = parameterInfos.size

/**
* The parameter type at index n. A hint about the raw parameter type is passed to make
* it easier for the implementation to make a guess based on runtime information.
* As Scala is a statically typed language, the javaType parameter is ignored
*/
def getParameterType(index: Int, javaType: Type) = {
new ParameterInfo(parameterInfos.get(index), null, null, null)
new ParameterInfo(parameterInfos(index), null, null, null)
}

/**
Expand All @@ -80,5 +80,4 @@ class ScalaStepDefinition(frame:StackTraceElement,
* @return the pattern associated with this instance. Used for error reporting only.
*/
def getPattern = pattern

}
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ Feature: Cukes
Scenario: Custom object with string constructor
Given I have a person Bob
Then he should say "Hello, I'm Bob!"

Scenario: Custom objects in the belly
Given I have eaten the following cukes
| Color | Number |
| Green | 1 |
| Red | 3 |
| Blue | 2 |
Then I should have eaten 6 cukes
And they should have been Green, Red, Blue
3 changes: 3 additions & 0 deletions scala/src/test/scala/cucumber/runtime/scala/model/Cuke.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package cucumber.runtime.scala.model

case class Cukes(number: Int, color: String)
Loading