From 2299b3beaece329311fe95bed4f396d26101fda2 Mon Sep 17 00:00:00 2001 From: sofusmortensen Date: Sun, 18 Sep 2016 18:09:00 +0200 Subject: [PATCH] Universal: fixed syntax issue that should have resulted in compile error --- .../r3corda/contracts/universal/literal.kt | 8 +++ .../contracts/universal/ContractDefinition.kt | 58 +++++++++++++++++-- .../r3corda/contracts/universal/Swaption.kt | 18 +++--- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/experimental/src/main/kotlin/com/r3corda/contracts/universal/literal.kt b/experimental/src/main/kotlin/com/r3corda/contracts/universal/literal.kt index e48595ec64..a205e1c209 100644 --- a/experimental/src/main/kotlin/com/r3corda/contracts/universal/literal.kt +++ b/experimental/src/main/kotlin/com/r3corda/contracts/universal/literal.kt @@ -90,6 +90,14 @@ open class ContractBuilder { fun String.givenThat(@Suppress("UNUSED_PARAMETER") ignore1: T, @Suppress("UNUSED_PARAMETER") ignore2: T) { } + @Deprecated(level = DeprecationLevel.ERROR, message = "Not available") + fun Party.may(init: ActionBuilder.() -> Action) { + } + + @Deprecated(level = DeprecationLevel.ERROR, message = "Not available") + fun Set.may(init: ActionBuilder.() -> Action) { + } + /* fun Party.gives(beneficiary: Party, amount: Perceivable, currency: Currency) { contracts.add( Transfer(amount, currency, this, beneficiary)) }*/ diff --git a/experimental/src/test/kotlin/com/r3corda/contracts/universal/ContractDefinition.kt b/experimental/src/test/kotlin/com/r3corda/contracts/universal/ContractDefinition.kt index b71967ab30..142fc5ac28 100644 --- a/experimental/src/test/kotlin/com/r3corda/contracts/universal/ContractDefinition.kt +++ b/experimental/src/test/kotlin/com/r3corda/contracts/universal/ContractDefinition.kt @@ -64,10 +64,12 @@ class ContractDefinition { actions { acmeCorp.may { "exercise".anytime { - (acmeCorp or highStreetBank).may { - "execute".givenThat(after("2017-09-01")) { - highStreetBank.gives(acmeCorp, 1.M, EUR) - acmeCorp.gives(highStreetBank, 1200.K, USD) + actions { + (acmeCorp or highStreetBank).may { + "execute".givenThat(after("2017-09-01")) { + highStreetBank.gives(acmeCorp, 1.M, EUR) + acmeCorp.gives(highStreetBank, 1200.K, USD) + } } } } @@ -81,8 +83,52 @@ class ContractDefinition { } - @Test - fun test() { + /* @Test + fun `builder problem - should not compile`() { + val arr = arrange { + actions { + acmeCorp.may { + "execute".anytime { + acmeCorp.may { + "problem".anytime { + highStreetBank.gives(acmeCorp, 1.M, USD) + } + } + } + } + } + } + assert( arr is Actions ) + + if (arr is Actions) { + assert( arr.actions.size == 1) + } } +*/ + @Test + fun `builder problem - legal`() { + val arr = arrange { + actions { + acmeCorp.may { + "execute".anytime { + actions { + acmeCorp.may { + "problem".anytime { + highStreetBank.gives(acmeCorp, 1.M, USD) + } + } + } + } + } + } + } + + assert( arr is Actions ) + + if (arr is Actions) { + assert( arr.actions.size == 1) + } + } + } \ No newline at end of file diff --git a/experimental/src/test/kotlin/com/r3corda/contracts/universal/Swaption.kt b/experimental/src/test/kotlin/com/r3corda/contracts/universal/Swaption.kt index 76d0d7a69e..139e88a6ec 100644 --- a/experimental/src/test/kotlin/com/r3corda/contracts/universal/Swaption.kt +++ b/experimental/src/test/kotlin/com/r3corda/contracts/universal/Swaption.kt @@ -22,15 +22,17 @@ class Swaption { "proceed".givenThat(after("01/07/2015")) { highStreetBank.gives(acmeCorp, libor(notional, "01/04/2015", "01/07/2015"), currency) acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/04/2015", "01/07/2015"), currency) - (highStreetBank or acmeCorp).may { - "proceed".givenThat(after("01/10/2015")) { - highStreetBank.gives(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency) - acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency) + actions { + (highStreetBank or acmeCorp).may { + "proceed".givenThat(after("01/10/2015")) { + highStreetBank.gives(acmeCorp, libor(notional, "01/07/2015", "01/10/2015"), currency) + acmeCorp.gives(highStreetBank, interest(notional, "act/365", coupon, "01/07/2015", "01/10/2015"), currency) - actions { - (highStreetBank or acmeCorp).may { - "dummy".anytime { zero } - // etc ... + actions { + (highStreetBank or acmeCorp).may { + "dummy".anytime { zero } + // etc ... + } } } }