universal: pretty print

This commit is contained in:
Sofus Mortensen 2017-01-08 18:41:51 +01:00
parent 306a3cdff7
commit bfd7aa4fc2
7 changed files with 69 additions and 1 deletions

View File

@ -78,6 +78,25 @@ private class PrettyPrint(arr : Arrangement) {
print(" or ") print(" or ")
prettyPrintPerBoolean(per.right) prettyPrintPerBoolean(per.right)
} }
is PerceivableAnd -> {
prettyPrintPerBoolean(per.left)
print(" and ")
prettyPrintPerBoolean(per.right)
}
is TimePerceivable -> {
when (per.cmp) {
Comparison.GT, Comparison.GTE -> {
print("after(")
prettyPrintPerInstant(per.instant)
print(")")
}
Comparison.LT, Comparison.LTE -> {
print("before(")
prettyPrintPerInstant(per.instant)
print(")")
}
}
}
is ActorPerceivable -> { is ActorPerceivable -> {
print("signedBy(${partyMap[per.actor.owningKey]})") print("signedBy(${partyMap[per.actor.owningKey]})")
} }
@ -113,6 +132,11 @@ private class PrettyPrint(arr : Arrangement) {
} }
prettyPrintPerBD(per.right) prettyPrintPerBD(per.right)
} }
is UnaryPlus -> {
print("(")
prettyPrintPerBD(per.arg)
print(".).plus()")
}
is Const -> { is Const -> {
print(per.value) print(per.value)
} }

View File

@ -51,7 +51,7 @@ private fun involvedPartiesVisitor(action: Action): Set<Party> =
private fun involvedPartiesVisitor(arrangement: Arrangement): ImmutableSet<Party> = private fun involvedPartiesVisitor(arrangement: Arrangement): ImmutableSet<Party> =
when (arrangement) { when (arrangement) {
is Zero -> ImmutableSet.of<Party>() is Zero -> ImmutableSet.of<Party>()
is Obligation -> ImmutableSet.of(arrangement.from) is Obligation -> ImmutableSet.of(arrangement.from, arrangement.to)
is RollOut -> involvedPartiesVisitor(arrangement.template) is RollOut -> involvedPartiesVisitor(arrangement.template)
is Continuation -> ImmutableSet.of<Party>() is Continuation -> ImmutableSet.of<Party>()
is And -> is And ->

View File

@ -314,5 +314,11 @@ class Cap {
@Test @Ignore @Test @Ignore
fun `pretty print`() { fun `pretty print`() {
println ( prettyPrint(contractInitial) ) println ( prettyPrint(contractInitial) )
println ( prettyPrint(contractAfterFixingFirst) )
println ( prettyPrint(contractAfterExecutionFirst) )
println ( prettyPrint(contractAfterFixingFinal) )
} }
} }

View File

@ -4,6 +4,7 @@ import net.corda.core.contracts.FixOf
import net.corda.core.contracts.Tenor import net.corda.core.contracts.Tenor
import net.corda.core.utilities.DUMMY_NOTARY import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction import net.corda.testing.transaction
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
import java.time.LocalDate import java.time.LocalDate
@ -131,4 +132,14 @@ class Caplet {
} }
} }
@Test @Ignore
fun `pretty print`() {
println ( prettyPrint(contract) )
println ( prettyPrint(contractFixed) )
println ( prettyPrint(contractFinal) )
}
} }

View File

@ -2,6 +2,7 @@ package net.corda.contracts.universal
import net.corda.core.utilities.DUMMY_NOTARY import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction import net.corda.testing.transaction
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
@ -132,4 +133,14 @@ class FXFwdTimeOption
this.verifies() this.verifies()
} }
} }
@Test @Ignore
fun `pretty print`() {
println ( prettyPrint(initialContract) )
println ( prettyPrint(outContract1) )
println ( prettyPrint(outContract2) )
}
} }

View File

@ -2,6 +2,7 @@ package net.corda.contracts.universal
import net.corda.core.utilities.DUMMY_NOTARY import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction import net.corda.testing.transaction
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
@ -175,4 +176,10 @@ class FXSwap {
this `fails with` "output states must match action result state" this `fails with` "output states must match action result state"
} }
} }
@Test @Ignore
fun `pretty print`() {
println ( prettyPrint(contract) )
}
} }

View File

@ -5,6 +5,7 @@ import net.corda.core.contracts.Frequency
import net.corda.core.contracts.Tenor import net.corda.core.contracts.Tenor
import net.corda.core.utilities.DUMMY_NOTARY import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction import net.corda.testing.transaction
import org.junit.Ignore
import org.junit.Test import org.junit.Test
import java.time.Instant import java.time.Instant
import java.time.LocalDate import java.time.LocalDate
@ -213,5 +214,13 @@ class IRS {
} }
} }
@Test @Ignore
fun `pretty print`() {
println ( prettyPrint(contractInitial) )
println ( prettyPrint(contractAfterFixingFirst) )
println ( prettyPrint(contractAfterExecutionFirst) )
}
} }