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

build(kotlin): Add spotless ktfmt and enable explicit api mode for library code. #1912

Merged
merged 9 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Comply with explicit API mode to library code.
  • Loading branch information
wywen committed Oct 26, 2024
commit e3a4f5769d1636db17de2b85d6e0104bbfbab65a
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,26 @@ package org.apache.fury.serializer.kotlin
/**
* Collection builder interface adapts an iterable to allow incremental build by the fury protocol.
*/
interface CollectionBuilder<E, T : Iterable<E>> {
fun add(element: E): Boolean
public interface CollectionBuilder<E, T : Iterable<E>> {
public fun add(element: E): Boolean

fun result(): T
public fun result(): T
}

/** Abstract builder for [kotlin.collections.List] interface. */
abstract class AbstractListBuilder<E, T : List<E>> :
public abstract class AbstractListBuilder<E, T : List<E>> :
CollectionBuilder<E, T>, AdaptedCollection<E>() {
protected open val builder: MutableList<E> = mutableListOf()
override val size: Int
get() = builder.size

override fun add(element: E) = builder.add(element)
override fun add(element: E): Boolean = builder.add(element)

override fun iterator(): MutableIterator<E> = builder.iterator()
}

/** Builder for [kotlin.collections.ArrayDeque]. */
class ArrayDequeBuilder<E>(override val builder: ArrayDeque<E>) :
public class ArrayDequeBuilder<E>(override val builder: ArrayDeque<E>) :
AbstractListBuilder<E, ArrayDeque<E>>() {
override fun result(): ArrayDeque<E> = builder
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import org.apache.fury.serializer.collection.AbstractCollectionSerializer

/** Serializer for kotlin collections. */
@Suppress("UNCHECKED_CAST")
abstract class AbstractKotlinCollectionSerializer<E, T : Iterable<E>>(fury: Fury, cls: Class<T>) :
public abstract class AbstractKotlinCollectionSerializer<E, T : Iterable<E>>(fury: Fury, cls: Class<T>) :
AbstractCollectionSerializer<T>(fury, cls) {
abstract override fun onCollectionWrite(buffer: MemoryBuffer, value: T): Collection<E>

Expand All @@ -43,7 +43,7 @@ abstract class AbstractKotlinCollectionSerializer<E, T : Iterable<E>>(fury: Fury
}

/** Serializer for [[kotlin.collections.ArrayDeque]]. */
class KotlinArrayDequeSerializer<E>(
public class KotlinArrayDequeSerializer<E>(
fury: Fury,
cls: Class<ArrayDeque<E>>,
) : AbstractKotlinCollectionSerializer<E, ArrayDeque<E>>(fury, cls) {
Expand All @@ -60,7 +60,7 @@ class KotlinArrayDequeSerializer<E>(
}
}

typealias AdaptedCollection<E> = java.util.AbstractCollection<E>
public typealias AdaptedCollection<E> = java.util.AbstractCollection<E>

/** An adapter which wraps a kotlin iterable into a [[java.util.Collection]]. */
private class IterableAdapter<E>(coll: Iterable<E>) : AdaptedCollection<E>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ import org.apache.fury.memory.MemoryBuffer
import org.apache.fury.serializer.ImmutableSerializer
import org.apache.fury.serializer.Serializer

class DurationSerializer(fury: Fury, needToWriteRef: Boolean) :
public class DurationSerializer(fury: Fury, needToWriteRef: Boolean) :
ImmutableSerializer<Duration>(fury, Duration::class.java, needToWriteRef) {

constructor(
public constructor(
fury: Fury,
) : this(fury, fury.config.isTimeRefIgnored)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package org.apache.fury.serializer.kotlin

import kotlin.random.Random

object KotlinToJavaClass {
internal object KotlinToJavaClass {
// Collections
val ArrayDequeClass = ArrayDeque::class.java
val EmptyListClass = emptyList<Any>().javaClass
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.fury.memory.MemoryBuffer
import org.apache.fury.serializer.Serializer
import org.apache.fury.type.Type

abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
public abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
fury: Fury,
cls: Class<T>,
private val delegateClass: Class<T_Delegate>
Expand All @@ -35,9 +35,9 @@ abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
// Lazily initialize the delegatingSerializer here to avoid lookup cost.
private val delegatingSerializer by lazy { fury.classResolver.getSerializer(delegateClass) }

abstract fun toDelegateClass(value: T): T_Delegate
protected abstract fun toDelegateClass(value: T): T_Delegate

abstract fun fromDelegateClass(value: T_Delegate): T
protected abstract fun fromDelegateClass(value: T_Delegate): T

override fun getXtypeId(): Short {
return (-Type.LIST.id).toShort()
Expand All @@ -61,62 +61,62 @@ abstract class AbstractDelegatingArraySerializer<T, T_Delegate>(
}
}

class UByteArraySerializer(
public class UByteArraySerializer(
fury: Fury,
) :
AbstractDelegatingArraySerializer<UByteArray, ByteArray>(
fury,
UByteArray::class.java,
ByteArray::class.java
) {
override fun toDelegateClass(value: UByteArray) = value.toByteArray()
override fun toDelegateClass(value: UByteArray): ByteArray = value.toByteArray()

override fun fromDelegateClass(value: ByteArray) = value.toUByteArray()
override fun fromDelegateClass(value: ByteArray): UByteArray = value.toUByteArray()

override fun copy(value: UByteArray): UByteArray = value.copyOf()
}

class UShortArraySerializer(
public class UShortArraySerializer(
fury: Fury,
) :
AbstractDelegatingArraySerializer<UShortArray, ShortArray>(
fury,
UShortArray::class.java,
ShortArray::class.java
) {
override fun toDelegateClass(value: UShortArray) = value.toShortArray()
override fun toDelegateClass(value: UShortArray): ShortArray = value.toShortArray()

override fun fromDelegateClass(value: ShortArray) = value.toUShortArray()
override fun fromDelegateClass(value: ShortArray): UShortArray = value.toUShortArray()

override fun copy(value: UShortArray) = value.copyOf()
override fun copy(value: UShortArray): UShortArray = value.copyOf()
}

class UIntArraySerializer(
public class UIntArraySerializer(
fury: Fury,
) :
AbstractDelegatingArraySerializer<UIntArray, IntArray>(
fury,
UIntArray::class.java,
IntArray::class.java
) {
override fun toDelegateClass(value: UIntArray) = value.toIntArray()
override fun toDelegateClass(value: UIntArray): IntArray = value.toIntArray()

override fun fromDelegateClass(value: IntArray) = value.toUIntArray()
override fun fromDelegateClass(value: IntArray): UIntArray = value.toUIntArray()

override fun copy(value: UIntArray) = value.copyOf()
override fun copy(value: UIntArray): UIntArray = value.copyOf()
}

class ULongArraySerializer(
public class ULongArraySerializer(
fury: Fury,
) :
AbstractDelegatingArraySerializer<ULongArray, LongArray>(
fury,
ULongArray::class.java,
LongArray::class.java
) {
override fun toDelegateClass(value: ULongArray) = value.toLongArray()
override fun toDelegateClass(value: ULongArray): LongArray = value.toLongArray()

override fun fromDelegateClass(value: LongArray) = value.toULongArray()
override fun fromDelegateClass(value: LongArray): ULongArray = value.toULongArray()

override fun copy(value: ULongArray) = value.copyOf()
override fun copy(value: ULongArray): ULongArray = value.copyOf()
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import org.apache.fury.type.Type
*
* UByte is mapped to Type.UINT8
*/
class UByteSerializer(
public class UByteSerializer(
fury: Fury,
) :
Serializers.CrossLanguageCompatibleSerializer<UByte>(
Expand All @@ -54,7 +54,7 @@ class UByteSerializer(
*
* UShort is mapped to Type.UINT16.
*/
class UShortSerializer(
public class UShortSerializer(
fury: Fury,
) :
Serializers.CrossLanguageCompatibleSerializer<UShort>(
Expand All @@ -78,7 +78,7 @@ class UShortSerializer(
*
* UInt is mapped to Type.UINT32.
*/
class UIntSerializer(
public class UIntSerializer(
fury: Fury,
) :
Serializers.CrossLanguageCompatibleSerializer<UInt>(
Expand All @@ -103,7 +103,7 @@ class UIntSerializer(
*
* ULong is mapped to Type.UINT64.
*/
class ULongSerializer(
public class ULongSerializer(
fury: Fury,
) :
Serializers.CrossLanguageCompatibleSerializer<ULong>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import org.apache.fury.memory.MemoryBuffer
import org.apache.fury.serializer.ImmutableSerializer

@OptIn(ExperimentalUuidApi::class)
class UuidSerializer(fury: Fury) : ImmutableSerializer<Uuid>(fury, Uuid::class.java) {
public class UuidSerializer(fury: Fury) : ImmutableSerializer<Uuid>(fury, Uuid::class.java) {
override fun write(buffer: MemoryBuffer, value: Uuid) {
value.toLongs { msb, lsb ->
buffer.writeInt64(msb)
Expand Down