From c66026e54bdfa436bc66a32d7f9de37398acba01 Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Fri, 8 Dec 2017 15:50:58 +0000 Subject: [PATCH 1/2] Code Cleanup --- .../serialization/CordaSerializationTransformRename.kt | 6 +++--- .../DeprecatedConstructorForDeserialization.kt | 4 ++-- .../core/serialization/MissingAttachmentsException.kt | 2 +- .../net/corda/core/serialization/SerializationToken.kt | 2 +- .../net/corda/core/transactions/SignedTransaction.kt | 2 +- .../nodeapi/internal/serialization/CordaClassResolver.kt | 9 ++++----- .../nodeapi/internal/serialization/DefaultWhitelist.kt | 4 ++-- .../serialization/amqp/AMQPDescriptorRegistry.kt | 2 +- .../internal/serialization/amqp/ArraySerializer.kt | 2 +- .../internal/serialization/amqp/CustomSerializer.kt | 4 ++-- .../internal/serialization/amqp/EvolutionSerializer.kt | 8 +++++--- .../serialization/carpenter/AMQPSchemaExtensions.kt | 3 ++- .../nodeapi/internal/serialization/carpenter/Schema.kt | 4 ++-- 13 files changed, 27 insertions(+), 25 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt b/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt index c8ae7e2aec..abd556bb99 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt @@ -18,11 +18,11 @@ annotation class CordaSerializationTransformRenames(vararg val value: CordaSeria // TODO When we have class renaming update the docs /** * This annotation is used to mark a class has having had a property element. It is used by the - * AMQP deserialiser to allow instances with different versions of the class on their Class Path + * AMQP deserializer to allow instances with different versions of the class on their Class Path * to successfully deserialize the object * - * NOTE: Renaming of the class itself is not be done with this annotation. For class renaming - * see ??? + * NOTE: Renaming of the class itself isn't done with this annotation or, at present, supported + * by Corda * * @property to [String] representation of the properties new name * @property from [String] representation of the properties old new diff --git a/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt b/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt index 71d2691e7e..ff76109f03 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/DeprecatedConstructorForDeserialization.kt @@ -2,10 +2,10 @@ package net.corda.core.serialization /** * This annotation is a marker to indicate which secondary constructors should be considered, and in which - * order, for evolving objects during their deserialisation. + * order, for evolving objects during their deserialization. * * Versions will be considered in descending order, currently duplicate versions will result in - * non deterministic behaviour when deserialising objects + * non deterministic behaviour when deserializing objects */ @Target(AnnotationTarget.CONSTRUCTOR) @Retention(AnnotationRetention.RUNTIME) diff --git a/core/src/main/kotlin/net/corda/core/serialization/MissingAttachmentsException.kt b/core/src/main/kotlin/net/corda/core/serialization/MissingAttachmentsException.kt index a5934be42d..0799e9a270 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/MissingAttachmentsException.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/MissingAttachmentsException.kt @@ -3,6 +3,6 @@ package net.corda.core.serialization import net.corda.core.CordaException import net.corda.core.crypto.SecureHash -/** Thrown during deserialisation to indicate that an attachment needed to construct the [WireTransaction] is not found. */ +/** Thrown during deserialization to indicate that an attachment needed to construct the [WireTransaction] is not found. */ @CordaSerializable class MissingAttachmentsException(val ids: List) : CordaException() \ No newline at end of file diff --git a/core/src/main/kotlin/net/corda/core/serialization/SerializationToken.kt b/core/src/main/kotlin/net/corda/core/serialization/SerializationToken.kt index 8ca6820711..9ec9fb75c0 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/SerializationToken.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/SerializationToken.kt @@ -6,7 +6,7 @@ import net.corda.core.serialization.SingletonSerializationToken.Companion.single /** * The interfaces and classes in this file allow large, singleton style classes to * mark themselves as needing converting to some form of token representation in the serialised form - * and converting back again when deserialising. + * and converting back again when deserializing. * * Typically these classes would be used for node services and subsystems that might become reachable from * Fibers and thus sucked into serialization when they are checkpointed. diff --git a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt index c34fd26065..015e745987 100644 --- a/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt +++ b/core/src/main/kotlin/net/corda/core/transactions/SignedTransaction.kt @@ -50,7 +50,7 @@ data class SignedTransaction(val txBits: SerializedBytes, @Volatile @Transient private var cachedTransaction: CoreTransaction? = null - /** Lazily calculated access to the deserialised/hashed transaction data. */ + /** Lazily calculated access to the deserialized/hashed transaction data. */ private val transaction: CoreTransaction get() = cachedTransaction ?: txBits.deserialize().apply { cachedTransaction = this } /** The id of the contained [WireTransaction]. */ diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolver.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolver.kt index d4c98fc1e1..c41d3fe3ef 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolver.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/CordaClassResolver.kt @@ -27,10 +27,8 @@ import java.util.* class CordaClassResolver(serializationContext: SerializationContext) : DefaultClassResolver() { val whitelist: ClassWhitelist = TransientClassWhiteList(serializationContext.whitelist) - /* - * These classes are assignment-compatible Java equivalents of Kotlin classes. - * The point is that we do not want to send Kotlin types "over the wire" via RPC. - */ + // These classes are assignment-compatible Java equivalents of Kotlin classes. + // The point is that we do not want to send Kotlin types "over the wire" via RPC. private val javaAliases: Map, Class<*>> = mapOf( listOf().javaClass to Collections.emptyList().javaClass, setOf().javaClass to Collections.emptySet().javaClass, @@ -176,7 +174,8 @@ class GlobalTransientClassWhiteList(delegate: ClassWhitelist) : AbstractMutableC } /** - * A whitelist that can be customised via the [net.corda.core.node.SerializationWhitelist], since it implements [MutableClassWhitelist]. + * A whitelist that can be customised via the [net.corda.core.serialization.SerializationWhitelist], + * since it implements [MutableClassWhitelist]. */ class TransientClassWhiteList(delegate: ClassWhitelist) : AbstractMutableClassWhitelist(Collections.synchronizedSet(mutableSetOf()), delegate) diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/DefaultWhitelist.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/DefaultWhitelist.kt index 8a5cdbcaa3..710939f8b2 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/DefaultWhitelist.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/DefaultWhitelist.kt @@ -49,8 +49,8 @@ object DefaultWhitelist : SerializationWhitelist { java.time.YearMonth::class.java, java.time.MonthDay::class.java, java.time.Period::class.java, - java.time.DayOfWeek::class.java, // No custom serialiser but it's an enum. - java.time.Month::class.java, // No custom serialiser but it's an enum. + java.time.DayOfWeek::class.java, // No custom serializer but it's an enum. + java.time.Month::class.java, // No custom serializer but it's an enum. java.util.Collections.emptyMap().javaClass, java.util.Collections.emptySet().javaClass, diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPDescriptorRegistry.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPDescriptorRegistry.kt index 78ef9dc52a..3907a86fe8 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPDescriptorRegistry.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/AMQPDescriptorRegistry.kt @@ -13,7 +13,7 @@ import org.apache.qpid.proton.amqp.UnsignedLong const val DESCRIPTOR_TOP_32BITS: Long = 0xc562L shl(32 + 16) /** - * AMQP desriptor ID's for our custom types. + * AMQP descriptor ID's for our custom types. * * NEVER DELETE OR CHANGE THE ID ASSOCIATED WITH A TYPE * diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt index 732723a493..06ddb2b264 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt @@ -21,7 +21,7 @@ open class ArraySerializer(override val type: Type, factory: SerializerFactory) // id to generate it properly (it will always return [[[Ljava.lang.type -> type[][][] // for example). // - // We *need* to retain knowledge for AMQP deserialisation weather that lowest primitive + // We *need* to retain knowledge for AMQP deserialization weather that lowest primitive // was boxed or unboxed so just infer it recursively private fun calcTypeName(type: Type): String = if (type.componentType().isArray()) { diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CustomSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CustomSerializer.kt index 870bfbaccc..408345fc68 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CustomSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/CustomSerializer.kt @@ -147,8 +147,8 @@ abstract class CustomSerializer : AMQPSerializer { * * @param clazz The type to be marshalled * @param withInheritance Whether subclasses of the class can also be marshalled. - * @param make A lambda for constructing an instance, that defaults to calling a constructor that expects a string. - * @param unmake A lambda that extracts the string value for an instance, that defaults to the [toString] method. + * @param maker A lambda for constructing an instance, that defaults to calling a constructor that expects a string. + * @param unmaker A lambda that extracts the string value for an instance, that defaults to the [toString] method. */ abstract class ToString(clazz: Class, withInheritance: Boolean = false, private val maker: (String) -> T = clazz.getConstructor(String::class.java).let { `constructor` -> diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt index 411e405aad..f06980e7fb 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt @@ -10,7 +10,7 @@ import kotlin.reflect.full.findAnnotation import kotlin.reflect.jvm.javaType /** - * Serializer for deserialising objects whose definition has changed since they + * Serializer for deserializing objects whose definition has changed since they * were serialised */ class EvolutionSerializer( @@ -38,7 +38,7 @@ class EvolutionSerializer( companion object { /** - * Unlike the generic deserialisation case where we need to locate the primary constructor + * Unlike the generic deserialization case where we need to locate the primary constructor * for the object (or our best guess) in the case of an object whose structure has changed * since serialisation we need to attempt to locate a constructor that we can use. I.e. * it's parameters match the serialised members and it will initialise any newly added @@ -47,7 +47,7 @@ class EvolutionSerializer( * TODO: Type evolution * TODO: rename annotation */ - internal fun getEvolverConstructor(type: Type, oldArgs: Map): KFunction? { + private fun getEvolverConstructor(type: Type, oldArgs: Map): KFunction? { val clazz: Class<*> = type.asClass()!! if (!isConcrete(clazz)) return null @@ -77,6 +77,8 @@ class EvolutionSerializer( * as it was serialised and the type descriptor of that type * @param new is the Serializer built for the Class as it exists now, not * how it was serialised and persisted. + * @param factory the [SerializerFactory] associated with the serialization + * context this serializer is being built for */ fun make(old: CompositeType, new: ObjectSerializer, factory: SerializerFactory): AMQPSerializer { diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/AMQPSchemaExtensions.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/AMQPSchemaExtensions.kt index 0bbdf01033..6a0c3c9784 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/AMQPSchemaExtensions.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/AMQPSchemaExtensions.kt @@ -6,6 +6,7 @@ import net.corda.nodeapi.internal.serialization.amqp.CompositeType import net.corda.nodeapi.internal.serialization.amqp.RestrictedType import net.corda.nodeapi.internal.serialization.amqp.Field as AMQPField import net.corda.nodeapi.internal.serialization.amqp.Schema as AMQPSchema +import net.corda.core.serialization.SerializationContext fun AMQPSchema.carpenterSchema(classloader: ClassLoader): CarpenterMetaSchema { val rtn = CarpenterMetaSchema.newInstance() @@ -34,7 +35,7 @@ fun AMQPField.typeAsString() = if (type == "*") requires[0] else type * b) add the class to the dependency tree in [carpenterSchemas] if it cannot be instantiated * at this time * - * @param classloader the class loader provided dby the [SerializationContext] + * @param classloader the class loader provided by the [SerializationContext] * @param carpenterSchemas structure that holds the dependency tree and list of classes that * need constructing * @param force by default a schema is not added to [carpenterSchemas] if it already exists diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt index 352ad498da..3660ce4d6d 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt @@ -9,7 +9,7 @@ enum class SchemaFlags { } /** - * A Schema is the representation of an object the Carpenter can contsruct + * A Schema is the representation of an object the Carpenter can construct * * Known Sub Classes * - [ClassSchema] @@ -111,7 +111,7 @@ class EnumSchema( } /** - * Factory object used by the serialiser when building [Schema]s based + * Factory object used by the serializer when building [Schema]s based * on an AMQP schema */ object CarpenterSchemaFactory { From 23292543903a3066086c1ebe917d909a773c2db6 Mon Sep 17 00:00:00 2001 From: Katelyn Baker Date: Fri, 8 Dec 2017 17:00:15 +0000 Subject: [PATCH 2/2] Additional comment corrections --- .../CordaSerializationTransformRename.kt | 2 +- .../internal/serialization/amqp/ArraySerializer.kt | 2 +- .../serialization/amqp/EvolutionSerializer.kt | 14 +++++++------- .../internal/serialization/carpenter/Schema.kt | 8 ++++---- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt b/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt index abd556bb99..dc37459899 100644 --- a/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt +++ b/core/src/main/kotlin/net/corda/core/serialization/CordaSerializationTransformRename.kt @@ -19,7 +19,7 @@ annotation class CordaSerializationTransformRenames(vararg val value: CordaSeria /** * This annotation is used to mark a class has having had a property element. It is used by the * AMQP deserializer to allow instances with different versions of the class on their Class Path - * to successfully deserialize the object + * to successfully deserialize the object. * * NOTE: Renaming of the class itself isn't done with this annotation or, at present, supported * by Corda diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt index 06ddb2b264..46046a88f2 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/ArraySerializer.kt @@ -22,7 +22,7 @@ open class ArraySerializer(override val type: Type, factory: SerializerFactory) // for example). // // We *need* to retain knowledge for AMQP deserialization weather that lowest primitive - // was boxed or unboxed so just infer it recursively + // was boxed or unboxed so just infer it recursively. private fun calcTypeName(type: Type): String = if (type.componentType().isArray()) { val typeName = calcTypeName(type.componentType()); "$typeName[]" diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt index f06980e7fb..797943cf93 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/amqp/EvolutionSerializer.kt @@ -11,7 +11,7 @@ import kotlin.reflect.jvm.javaType /** * Serializer for deserializing objects whose definition has changed since they - * were serialised + * were serialised. */ class EvolutionSerializer( clazz: Type, @@ -40,9 +40,9 @@ class EvolutionSerializer( /** * Unlike the generic deserialization case where we need to locate the primary constructor * for the object (or our best guess) in the case of an object whose structure has changed - * since serialisation we need to attempt to locate a constructor that we can use. I.e. - * it's parameters match the serialised members and it will initialise any newly added - * elements + * since serialisation we need to attempt to locate a constructor that we can use. For example, + * its parameters match the serialised members and it will initialise any newly added + * elements. * * TODO: Type evolution * TODO: rename annotation @@ -70,8 +70,8 @@ class EvolutionSerializer( } /** - * Build a serialization object for deserialisation only of objects serialised - * as different versions of a class + * Build a serialization object for deserialization only of objects serialised + * as different versions of a class. * * @param old is an object holding the schema that represents the object * as it was serialised and the type descriptor of that type @@ -119,7 +119,7 @@ class EvolutionSerializer( * to the object list of values we need to map that list, which is ordered per the * constructor of the original state of the object, we need to map the new parameter order * of the current constructor onto that list inserting nulls where new parameters are - * encountered + * encountered. * * TODO: Object references */ diff --git a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt index 3660ce4d6d..a5de6bf2b0 100644 --- a/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt +++ b/node-api/src/main/kotlin/net/corda/nodeapi/internal/serialization/carpenter/Schema.kt @@ -62,7 +62,7 @@ fun EnumMap.simpleFieldAccess(): Boolean { } /** - * Represents a concrete object + * Represents a concrete object. */ class ClassSchema( name: String, @@ -77,7 +77,7 @@ class ClassSchema( /** * Represents an interface. Carpented interfaces can be used within [ClassSchema]s - * if that class should be implementing that interface + * if that class should be implementing that interface. */ class InterfaceSchema( name: String, @@ -91,7 +91,7 @@ class InterfaceSchema( } /** - * Represents an enumerated type + * Represents an enumerated type. */ class EnumSchema( name: String, @@ -112,7 +112,7 @@ class EnumSchema( /** * Factory object used by the serializer when building [Schema]s based - * on an AMQP schema + * on an AMQP schema. */ object CarpenterSchemaFactory { fun newInstance(