mirror of
https://github.com/corda/corda.git
synced 2025-05-03 17:23:03 +00:00
Code tidy up, auto reformat, IntelliJ suggestions
This commit is contained in:
parent
32ea59d085
commit
afdf5fb717
@ -27,9 +27,9 @@ import java.util.*
|
|||||||
* transformation rules we create a mapping between those values and the values that exist on the
|
* transformation rules we create a mapping between those values and the values that exist on the
|
||||||
* current class
|
* current class
|
||||||
*
|
*
|
||||||
* @property clazz The enum as it exists now, not as it did when it was serialized (either in the past
|
* @property type The enum as it exists now, not as it did when it was serialized (either in the past
|
||||||
* or future).
|
* or future).
|
||||||
* @property factory the [SerializerFactory] that is building this serialization object.
|
* @param factory the [SerializerFactory] that is building this serialization object.
|
||||||
* @property conversions A mapping between all potential enum constants that could've been assigned to
|
* @property conversions A mapping between all potential enum constants that could've been assigned to
|
||||||
* an instance of the enum as it existed at time of serialisation and those that exist now
|
* an instance of the enum as it existed at time of serialisation and those that exist now
|
||||||
* @property ordinals Convenience mapping of constant to ordinality
|
* @property ordinals Convenience mapping of constant to ordinality
|
||||||
@ -57,7 +57,7 @@ class EnumEvolutionSerializer(
|
|||||||
* received AMQP header
|
* received AMQP header
|
||||||
* @param new The Serializer object we built based on the current state of the enum class on our classpath
|
* @param new The Serializer object we built based on the current state of the enum class on our classpath
|
||||||
* @param factory the [SerializerFactory] that is building this serialization object.
|
* @param factory the [SerializerFactory] that is building this serialization object.
|
||||||
* @param transformsFromBlob the transforms attached to the class in the AMQP header, i.e. the transforms
|
* @param schemas the transforms attached to the class in the AMQP header, i.e. the transforms
|
||||||
* known at serialization time
|
* known at serialization time
|
||||||
*/
|
*/
|
||||||
fun make(old: RestrictedType,
|
fun make(old: RestrictedType,
|
||||||
|
@ -32,16 +32,15 @@ sealed class PropertySerializer(val name: String, val readMethod: Method?, val r
|
|||||||
return if (isInterface) listOf(SerializerFactory.nameForType(resolvedType)) else emptyList()
|
return if (isInterface) listOf(SerializerFactory.nameForType(resolvedType)) else emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDefault(): String? {
|
private fun generateDefault(): String? =
|
||||||
if (isJVMPrimitive) {
|
if (isJVMPrimitive) {
|
||||||
return when (resolvedType) {
|
when (resolvedType) {
|
||||||
java.lang.Boolean.TYPE -> "false"
|
java.lang.Boolean.TYPE -> "false"
|
||||||
java.lang.Character.TYPE -> "�"
|
java.lang.Character.TYPE -> "�"
|
||||||
else -> "0"
|
else -> "0"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return null
|
null
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateMandatory(): Boolean {
|
private fun generateMandatory(): Boolean {
|
||||||
|
@ -28,7 +28,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
Unknown({ UnknownTransform() }) {
|
Unknown({ UnknownTransform() }) {
|
||||||
override fun getDescriptor(): Any = DESCRIPTOR
|
override fun getDescriptor(): Any = DESCRIPTOR
|
||||||
override fun getDescribed(): Any = ordinal
|
override fun getDescribed(): Any = ordinal
|
||||||
override fun validate(l : List<Transform>, constants: Map<String, Int>) { }
|
override fun validate(list: List<Transform>, constants: Map<String, Int>) {}
|
||||||
},
|
},
|
||||||
EnumDefault({ a -> EnumDefaultSchemaTransform((a as CordaSerializationTransformEnumDefault).old, a.new) }) {
|
EnumDefault({ a -> EnumDefaultSchemaTransform((a as CordaSerializationTransformEnumDefault).old, a.new) }) {
|
||||||
override fun getDescriptor(): Any = DESCRIPTOR
|
override fun getDescriptor(): Any = DESCRIPTOR
|
||||||
@ -39,7 +39,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
* that should be used when we cannot use the new value) must refer to a constant that exists in the
|
* that should be used when we cannot use the new value) must refer to a constant that exists in the
|
||||||
* enum class as it exists now and it cannot refer to itself.
|
* enum class as it exists now and it cannot refer to itself.
|
||||||
*
|
*
|
||||||
* @param l The list of transforms representing new constants and the mapping from that constant to an
|
* @param list The list of transforms representing new constants and the mapping from that constant to an
|
||||||
* existing value
|
* existing value
|
||||||
* @param constants The list of enum constants on the type the transforms are being applied to
|
* @param constants The list of enum constants on the type the transforms are being applied to
|
||||||
*/
|
*/
|
||||||
@ -76,15 +76,16 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
* that is a constant is renamed to something that used to exist in the enum. We do this for both
|
* that is a constant is renamed to something that used to exist in the enum. We do this for both
|
||||||
* the same constant (i.e. C -> D -> C) and multiple constants (C->D, B->C)
|
* the same constant (i.e. C -> D -> C) and multiple constants (C->D, B->C)
|
||||||
*
|
*
|
||||||
* @param l The list of transforms representing the renamed constants and the mapping between their new
|
* @param list The list of transforms representing the renamed constants and the mapping between their new
|
||||||
* and old values
|
* and old values
|
||||||
* @param constants The list of enum constants on the type the transforms are being applied to
|
* @param constants The list of enum constants on the type the transforms are being applied to
|
||||||
*/
|
*/
|
||||||
override fun validate(l : List<Transform>, constants: Map<String, Int>) {
|
override fun validate(list: List<Transform>, constants: Map<String, Int>) {
|
||||||
object : Any() {
|
object : Any() {
|
||||||
val from: MutableSet<String> = mutableSetOf()
|
val from: MutableSet<String> = mutableSetOf()
|
||||||
val to : MutableSet<String> = mutableSetOf() }.apply {
|
val to: MutableSet<String> = mutableSetOf()
|
||||||
@Suppress("UNCHECKED_CAST") (l as List<RenameSchemaTransform>).forEach { rename ->
|
}.apply {
|
||||||
|
@Suppress("UNCHECKED_CAST") (list as List<RenameSchemaTransform>).forEach { rename ->
|
||||||
if (rename.to in this.to || rename.from in this.from) {
|
if (rename.to in this.to || rename.from in this.from) {
|
||||||
throw NotSerializableException("Cyclic renames are not allowed (${rename.to})")
|
throw NotSerializableException("Cyclic renames are not allowed (${rename.to})")
|
||||||
}
|
}
|
||||||
@ -104,7 +105,7 @@ enum class TransformTypes(val build: (Annotation) -> Transform) : DescribedType
|
|||||||
//}
|
//}
|
||||||
;
|
;
|
||||||
|
|
||||||
abstract fun validate(l: List<Transform>, constants: Map<String, Int>)
|
abstract fun validate(list: List<Transform>, constants: Map<String, Int>)
|
||||||
|
|
||||||
companion object : DescribedTypeConstructor<TransformTypes> {
|
companion object : DescribedTypeConstructor<TransformTypes> {
|
||||||
val DESCRIPTOR = AMQPDescriptorRegistry.TRANSFORM_ELEMENT_KEY.amqpDescriptor
|
val DESCRIPTOR = AMQPDescriptorRegistry.TRANSFORM_ELEMENT_KEY.amqpDescriptor
|
||||||
|
@ -6,7 +6,6 @@ import org.assertj.core.api.Assertions
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
package net.corda.nodeapi.internal.serialization.amqp
|
package net.corda.nodeapi.internal.serialization.amqp
|
||||||
|
|
||||||
import net.corda.core.serialization.*
|
import net.corda.core.serialization.CordaSerializationTransformEnumDefault
|
||||||
|
import net.corda.core.serialization.CordaSerializationTransformEnumDefaults
|
||||||
|
import net.corda.core.serialization.SerializedBytes
|
||||||
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
||||||
import org.assertj.core.api.Assertions
|
import org.assertj.core.api.Assertions
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
// NOTE: To recreate the test files used by these tests uncomment the original test classes and comment
|
// NOTE: To recreate the test files used by these tests uncomment the original test classes and comment
|
||||||
@ -149,7 +150,7 @@ class EnumEvolveTests {
|
|||||||
data class C(val e: DeserializeWithRename)
|
data class C(val e: DeserializeWithRename)
|
||||||
|
|
||||||
// Uncomment to re-generate test files, needs to be done in three stages
|
// Uncomment to re-generate test files, needs to be done in three stages
|
||||||
val so = SerializationOutput(sf)
|
// val so = SerializationOutput(sf)
|
||||||
// First change
|
// First change
|
||||||
// File(URI("$localPath/$resource.1.AA")).writeBytes(so.serialize(C(DeserializeWithRename.AA)).bytes)
|
// File(URI("$localPath/$resource.1.AA")).writeBytes(so.serialize(C(DeserializeWithRename.AA)).bytes)
|
||||||
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(DeserializeWithRename.B)).bytes)
|
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(DeserializeWithRename.B)).bytes)
|
||||||
@ -271,7 +272,7 @@ class EnumEvolveTests {
|
|||||||
data class C(val e: MultiOperations)
|
data class C(val e: MultiOperations)
|
||||||
|
|
||||||
// Uncomment to re-generate test files, needs to be done in three stages
|
// Uncomment to re-generate test files, needs to be done in three stages
|
||||||
val so = SerializationOutput(sf)
|
// val so = SerializationOutput(sf)
|
||||||
// First change
|
// First change
|
||||||
// File(URI("$localPath/$resource.1.A")).writeBytes(so.serialize(C(MultiOperations.A)).bytes)
|
// File(URI("$localPath/$resource.1.A")).writeBytes(so.serialize(C(MultiOperations.A)).bytes)
|
||||||
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(MultiOperations.B)).bytes)
|
// File(URI("$localPath/$resource.1.B")).writeBytes(so.serialize(C(MultiOperations.B)).bytes)
|
||||||
|
@ -2,17 +2,14 @@ package net.corda.nodeapi.internal.serialization.amqp
|
|||||||
|
|
||||||
import net.corda.core.serialization.ClassWhitelist
|
import net.corda.core.serialization.ClassWhitelist
|
||||||
import net.corda.core.serialization.CordaSerializable
|
import net.corda.core.serialization.CordaSerializable
|
||||||
import org.junit.Test
|
|
||||||
import java.time.DayOfWeek
|
|
||||||
|
|
||||||
import kotlin.test.assertEquals
|
|
||||||
import kotlin.test.assertNotNull
|
|
||||||
|
|
||||||
import java.io.File
|
|
||||||
import java.io.NotSerializableException
|
|
||||||
|
|
||||||
import net.corda.core.serialization.SerializedBytes
|
import net.corda.core.serialization.SerializedBytes
|
||||||
import org.assertj.core.api.Assertions
|
import org.assertj.core.api.Assertions
|
||||||
|
import org.junit.Test
|
||||||
|
import java.io.File
|
||||||
|
import java.io.NotSerializableException
|
||||||
|
import java.time.DayOfWeek
|
||||||
|
import kotlin.test.assertEquals
|
||||||
|
import kotlin.test.assertNotNull
|
||||||
|
|
||||||
class EnumTests {
|
class EnumTests {
|
||||||
enum class Bras {
|
enum class Bras {
|
||||||
@ -42,8 +39,8 @@ class EnumTests {
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// the new state, note in the test we serialised with value UNDERWIRE so the spacer
|
// the new state, note in the test we serialised with value UNDERWIRE so the spacer
|
||||||
// occuring after this won't have changed the ordinality of our serialised value
|
// occurring after this won't have changed the ordinality of our serialised value
|
||||||
// and thus should still be deserialisable
|
// and thus should still be deserializable
|
||||||
enum class OldBras2 {
|
enum class OldBras2 {
|
||||||
TSHIRT, UNDERWIRE, PUSHUP, SPACER, BRALETTE, SPACER2
|
TSHIRT, UNDERWIRE, PUSHUP, SPACER, BRALETTE, SPACER2
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,6 @@ import net.corda.testing.common.internal.ProjectStructure.projectRootDir
|
|||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.NotSerializableException
|
import java.io.NotSerializableException
|
||||||
import java.net.URI
|
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
// To regenerate any of the binary test files do the following
|
// To regenerate any of the binary test files do the following
|
||||||
@ -19,6 +18,7 @@ import kotlin.test.assertEquals
|
|||||||
// 5. Comment back out the generation code and uncomment the actual test
|
// 5. Comment back out the generation code and uncomment the actual test
|
||||||
class EvolvabilityTests {
|
class EvolvabilityTests {
|
||||||
// When regenerating the test files this needs to be set to the file system location of the resource files
|
// When regenerating the test files this needs to be set to the file system location of the resource files
|
||||||
|
@Suppress("UNUSED")
|
||||||
var localPath = projectRootDir.toUri().resolve(
|
var localPath = projectRootDir.toUri().resolve(
|
||||||
"node-api/src/test/resources/net/corda/nodeapi/internal/serialization/amqp")
|
"node-api/src/test/resources/net/corda/nodeapi/internal/serialization/amqp")
|
||||||
|
|
||||||
@ -369,6 +369,7 @@ class EvolvabilityTests {
|
|||||||
|
|
||||||
// Add a parameter to inner but keep outer unchanged
|
// Add a parameter to inner but keep outer unchanged
|
||||||
data class Inner(val a: Int, val b: String?)
|
data class Inner(val a: Int, val b: String?)
|
||||||
|
|
||||||
data class Outer(val a: Int, val b: Inner)
|
data class Outer(val a: Int, val b: Inner)
|
||||||
|
|
||||||
val path = EvolvabilityTests::class.java.getResource(resource)
|
val path = EvolvabilityTests::class.java.getResource(resource)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user