Update plugin spotless to v6.14.0 (#1620)

* Update plugin spotless to v6.14.0

* Update Spotless version and apply

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Jake Wharton <jw@squareup.com>
This commit is contained in:
renovate[bot]
2023-01-30 14:03:50 +00:00
committed by GitHub
parent 187f9f03b8
commit e6110de8c3
67 changed files with 546 additions and 495 deletions

View File

@@ -62,7 +62,7 @@ tasks.withType<KotlinCompile>()
kotlinOptions {
val toAdd = mutableListOf(
"-opt-in=kotlin.contracts.ExperimentalContracts",
"-Xjvm-default=all"
"-Xjvm-default=all",
)
if (name.contains("test", true)) {
toAdd += "-opt-in=kotlin.ExperimentalStdlibApi"

View File

@@ -29,12 +29,12 @@ import java.lang.reflect.Type
internal class AdapterMethodsFactory(
private val toAdapters: List<AdapterMethod>,
private val fromAdapters: List<AdapterMethod>
private val fromAdapters: List<AdapterMethod>,
) : JsonAdapter.Factory {
override fun create(
type: Type,
annotations: Set<Annotation>,
moshi: Moshi
moshi: Moshi,
): JsonAdapter<*>? {
val toAdapter = get(toAdapters, type, annotations)
val fromAdapter = get(fromAdapters, type, annotations)
@@ -47,7 +47,7 @@ internal class AdapterMethodsFactory(
val missingAnnotation = if (toAdapter == null) "@ToJson" else "@FromJson"
throw IllegalArgumentException(
"No $missingAnnotation adapter for ${type.toStringWithAnnotations(annotations)}",
e
e,
)
}
} else {
@@ -154,7 +154,7 @@ internal class AdapterMethodsFactory(
annotations = qualifierAnnotations,
adapter = adapter,
method = method,
nullable = true
nullable = true,
) {
override fun toJson(moshi: Moshi, writer: JsonWriter, value: Any?) {
invokeMethod(writer, value)
@@ -173,7 +173,7 @@ internal class AdapterMethodsFactory(
annotations = qualifierAnnotations,
adapter = adapter,
method = method,
nullable = nullable
nullable = nullable,
) {
private lateinit var delegate: JsonAdapter<Any>
@@ -203,7 +203,7 @@ internal class AdapterMethodsFactory(
<any access modifier> void toJson(JsonWriter writer, T value, JsonAdapter<any> delegate, <any more delegates>) throws <any>;
<any access modifier> R toJson(T value) throws <any>;
""".trimIndent()
""".trimIndent(),
)
}
}
@@ -244,7 +244,7 @@ internal class AdapterMethodsFactory(
annotations = returnTypeAnnotations,
adapter = adapter,
method = method,
nullable = true
nullable = true,
) {
override fun fromJson(moshi: Moshi, reader: JsonReader) = invokeMethod(reader)
}
@@ -260,7 +260,7 @@ internal class AdapterMethodsFactory(
annotations = returnTypeAnnotations,
adapter = adapter,
method = method,
nullable = nullable
nullable = nullable,
) {
lateinit var delegate: JsonAdapter<Any>
@@ -288,7 +288,7 @@ internal class AdapterMethodsFactory(
<any access modifier> R fromJson(JsonReader jsonReader, JsonAdapter<any> delegate, <any more delegates>) throws <any>;
<any access modifier> R fromJson(T value) throws <any>;
""".trimIndent()
""".trimIndent(),
)
}
}
@@ -298,7 +298,7 @@ internal class AdapterMethodsFactory(
private fun get(
adapterMethods: List<AdapterMethod>,
type: Type,
annotations: Set<Annotation>
annotations: Set<Annotation>,
): AdapterMethod? {
for (adapterMethod in adapterMethods) {
if (Types.equals(adapterMethod.type, type) && adapterMethod.annotations == annotations) {
@@ -316,7 +316,7 @@ internal class AdapterMethodsFactory(
val annotations: Set<Annotation>,
val adapter: Any,
val method: Method,
val nullable: Boolean
val nullable: Boolean,
) {
val type = type.canonicalize()
private val jsonAdapters: Array<JsonAdapter<*>?> = arrayOfNulls(parameterCount - adaptersOffset)

View File

@@ -24,7 +24,7 @@ import java.lang.reflect.Array as JavaArray
*/
internal class ArrayJsonAdapter(
private val elementClass: Class<*>,
private val elementAdapter: JsonAdapter<Any>
private val elementAdapter: JsonAdapter<Any>,
) : JsonAdapter<Any?>() {
override fun fromJson(reader: JsonReader): Any {
val list = buildList<Any?> {

View File

@@ -87,7 +87,7 @@ internal abstract class ClassFactory<T> {
val newInstance = ObjectStreamClass::class.java.getDeclaredMethod(
"newInstance",
Class::class.java,
Int::class.javaPrimitiveType
Int::class.javaPrimitiveType,
)
newInstance.isAccessible = true
return object : ClassFactory<T>() {

View File

@@ -49,7 +49,7 @@ import java.lang.reflect.Type
*/
internal class ClassJsonAdapter<T>(
private val classFactory: ClassFactory<T>,
fieldsMap: Map<String, FieldBinding<*>>
fieldsMap: Map<String, FieldBinding<*>>,
) : JsonAdapter<T>() {
private val fieldsArray = fieldsMap.values.toTypedArray()
private val options = JsonReader.Options.of(*fieldsMap.keys.toTypedArray())
@@ -115,7 +115,7 @@ internal class ClassJsonAdapter<T>(
override fun create(
type: Type,
annotations: Set<Annotation>,
moshi: Moshi
moshi: Moshi,
): JsonAdapter<*>? {
if (type !is Class<*> && type !is ParameterizedType) {
return null
@@ -136,7 +136,7 @@ internal class ClassJsonAdapter<T>(
}
}
throw IllegalArgumentException(
"$messagePrefix requires explicit JsonAdapter to be registered"
"$messagePrefix requires explicit JsonAdapter to be registered",
)
}
@@ -185,7 +185,7 @@ internal class ClassJsonAdapter<T>(
private fun createFieldBindings(
moshi: Moshi,
type: Type,
fieldBindings: MutableMap<String, FieldBinding<*>>
fieldBindings: MutableMap<String, FieldBinding<*>>,
) {
val rawType = type.rawType
val platformType = rawType.isPlatformType
@@ -201,7 +201,7 @@ internal class ClassJsonAdapter<T>(
val adapter = moshi.adapter<Any>(
type = fieldType,
annotations = annotations,
fieldName = fieldName
fieldName = fieldName,
)
// Create the binding between field and JSON.

View File

@@ -20,7 +20,7 @@ import java.lang.reflect.Type
/** Converts collection types to JSON arrays containing their converted contents. */
internal abstract class CollectionJsonAdapter<C : MutableCollection<T?>, T> private constructor(
private val elementAdapter: JsonAdapter<T>
private val elementAdapter: JsonAdapter<T>,
) : JsonAdapter<C>() {
abstract fun newCollection(): C

View File

@@ -39,7 +39,7 @@ public annotation class Json(
*
* **Note:** this has no effect in `enum` or `record` classes.
*/
val ignore: Boolean = false
val ignore: Boolean = false,
) {
public companion object {
/** The default value of [name]. Should only be used to check if it's been set. */

View File

@@ -63,5 +63,5 @@ public annotation class JsonClass(
* generator to create the API signature to get started, then make your own generator match that
* expected signature.
*/
val generator: String = ""
val generator: String = "",
)

View File

@@ -230,7 +230,6 @@ public sealed class JsonReader : Closeable {
* useful in development and debugging because it means a typo like "locatiom" will be detected
* early. It's potentially harmful in production because it complicates revising a JSON schema.
*/
/** Returns true if this parser forbids skipping names and values. */
@get:JvmName("failOnUnknown")
public var failOnUnknown: Boolean = false
@@ -578,7 +577,7 @@ public sealed class JsonReader : Closeable {
*/
public class Options private constructor(
internal val strings: Array<out String>,
internal val doubleQuoteSuffix: OkioOptions
internal val doubleQuoteSuffix: OkioOptions,
) {
/** Returns a copy of this [Option's][Options] strings. */
public fun strings(): List<String> {
@@ -657,7 +656,7 @@ public sealed class JsonReader : Closeable {
* The end of the JSON stream. This sentinel value is returned by [JsonReader.peek] to
* signal that the JSON-encoded value has no more tokens.
*/
END_DOCUMENT
END_DOCUMENT,
}
public companion object {

View File

@@ -530,7 +530,9 @@ internal class JsonUtf8Reader : JsonReader {
peeked = PEEKED_NONE
pathNames[stackSize - 1] = name
i
} else -1
} else {
-1
}
}
override fun nextString(): String {
@@ -586,7 +588,9 @@ internal class JsonUtf8Reader : JsonReader {
peeked = PEEKED_NONE
pathIndices[stackSize - 1]++
i
} else -1
} else {
-1
}
}
override fun nextBoolean(): Boolean {

View File

@@ -37,7 +37,7 @@ import kotlin.require
internal class JsonUtf8Writer(
/** The output data, containing at most one top-level array or object. */
private val sink: BufferedSink
private val sink: BufferedSink,
) : JsonWriter() {
/** The name/value separator; either ":" or ": ". */

View File

@@ -381,7 +381,7 @@ internal class JsonValueReader : JsonReader {
internal class JsonIterator(
val endToken: Token,
val array: Array<Any?>,
var next: Int
var next: Int,
) : Iterator<Any?>, Cloneable {
override fun hasNext() = next < array.size

View File

@@ -47,7 +47,7 @@ internal class JsonValueSource @JvmOverloads constructor(
* reached, this should be compared against 0. If it is zero, then we've read a complete value and
* this source is exhausted.
*/
private var stackSize: Int = 0
private var stackSize: Int = 0,
) : Source {
private val buffer: Buffer = source.buffer

View File

@@ -158,6 +158,7 @@ public sealed class JsonWriter : Closeable, Flushable {
* the encoded document will be compact.
*/
get() = _indent.orEmpty()
/**
* Sets the indentation string to be repeated for each level of indentation in the encoded
* document. If `indent.isEmpty()` the encoded document will be compact. Otherwise, the

View File

@@ -22,7 +22,7 @@ internal class LinkedHashTreeMap<K, V>
* @param comparator the comparator to order elements with, or null to use the natural ordering.
*/
constructor(
comparator: Comparator<Any?>? = null
comparator: Comparator<Any?>? = null,
) : AbstractMutableMap<K, V>(), Serializable {
@Suppress("UNCHECKED_CAST")
private val comparator: Comparator<Any?> = (comparator ?: NATURAL_ORDER) as Comparator<Any?>
@@ -83,6 +83,7 @@ constructor(
@JvmField
var next: Node<K, V>?
@JvmField
var prev: Node<K, V>?

View File

@@ -51,7 +51,7 @@ internal class MapJsonAdapter<K, V>(moshi: Moshi, keyType: Type, valueType: Type
val replaced = result.put(name, value)
if (replaced != null) {
throw JsonDataException(
"Map key '$name' has multiple values at path ${reader.path}: $replaced and $value"
"Map key '$name' has multiple values at path ${reader.path}: $replaced and $value",
)
}
}

View File

@@ -107,7 +107,7 @@ public class Moshi internal constructor(builder: Builder) {
public fun <T> adapter(
type: Type,
annotations: Set<Annotation>,
fieldName: String?
fieldName: String?,
): JsonAdapter<T> {
val cleanedType = type.canonicalize().removeSubtypeWildcard()
@@ -150,7 +150,7 @@ public class Moshi internal constructor(builder: Builder) {
public fun <T> nextAdapter(
skipPast: JsonAdapter.Factory,
type: Type,
annotations: Set<Annotation>
annotations: Set<Annotation>,
): JsonAdapter<T> {
val cleanedType = type.canonicalize().removeSubtypeWildcard()
val skipPastIndex = factories.indexOf(skipPast)
@@ -203,7 +203,7 @@ public class Moshi internal constructor(builder: Builder) {
public fun <T> add(
type: Type,
annotation: Class<out Annotation>,
jsonAdapter: JsonAdapter<T>
jsonAdapter: JsonAdapter<T>,
): Builder = apply {
add(newAdapterFactory(type, annotation, jsonAdapter))
}
@@ -225,7 +225,7 @@ public class Moshi internal constructor(builder: Builder) {
public fun <T> addLast(
type: Type,
annotation: Class<out Annotation>,
jsonAdapter: JsonAdapter<T>
jsonAdapter: JsonAdapter<T>,
): Builder = apply {
addLast(newAdapterFactory(type, annotation, jsonAdapter))
}
@@ -373,7 +373,7 @@ public class Moshi internal constructor(builder: Builder) {
fun <T> newAdapterFactory(
type: Type,
jsonAdapter: JsonAdapter<T>
jsonAdapter: JsonAdapter<T>,
): JsonAdapter.Factory {
return JsonAdapter.Factory { targetType, annotations, _ ->
if (annotations.isEmpty() && typesMatch(type, targetType)) jsonAdapter else null
@@ -383,7 +383,7 @@ public class Moshi internal constructor(builder: Builder) {
fun <T> newAdapterFactory(
type: Type,
annotation: Class<out Annotation>,
jsonAdapter: JsonAdapter<T>
jsonAdapter: JsonAdapter<T>,
): JsonAdapter.Factory {
require(annotation.isAnnotationPresent(JsonQualifier::class.java)) { "$annotation does not have @JsonQualifier" }
require(annotation.declaredMethods.isEmpty()) { "Use JsonAdapter.Factory for annotations with elements" }

View File

@@ -53,7 +53,9 @@ internal object StandardJsonAdapters : JsonAdapter.Factory {
return if (rawType.isEnum) {
@Suppress("UNCHECKED_CAST")
EnumJsonAdapter(rawType as Class<out Enum<*>>).nullSafe()
} else null
} else {
null
}
}
fun rangeCheckNextInt(reader: JsonReader, typeMessage: String?, min: Int, max: Int): Int {
@@ -120,7 +122,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory {
// Double check for infinity after float conversion; many doubles > Float.MAX
if (!reader.lenient && value.isInfinite()) {
throw JsonDataException(
"JSON forbids NaN and infinities: $value at path ${reader.path}"
"JSON forbids NaN and infinities: $value at path ${reader.path}",
)
}
return value
@@ -207,7 +209,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory {
val path = reader.path
val name = reader.nextString()
throw JsonDataException(
"Expected one of ${nameStrings.toList()} but was $name at path $path"
"Expected one of ${nameStrings.toList()} but was $name at path $path",
)
}
@@ -242,7 +244,7 @@ internal object StandardJsonAdapters : JsonAdapter.Factory {
JsonReader.Token.BOOLEAN -> booleanAdapter.fromJson(reader)
JsonReader.Token.NULL -> reader.nextNull()
else -> throw IllegalStateException(
"Expected a value but was ${reader.peek()} at path ${reader.path}"
"Expected a value but was ${reader.peek()} at path ${reader.path}",
)
}
}

View File

@@ -14,6 +14,7 @@
* limitations under the License.
*/
@file:Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
package com.squareup.moshi
import com.squareup.moshi.internal.EMPTY_TYPE_ARRAY
@@ -74,7 +75,7 @@ public object Types {
@JvmStatic
public fun nextAnnotations(
annotations: Set<Annotation>,
jsonQualifier: Class<out Annotation?>
jsonQualifier: Class<out Annotation?>,
): Set<Annotation>? {
require(jsonQualifier.isAnnotationPresent(JsonQualifier::class.java)) {
"$jsonQualifier is not a JsonQualifier."
@@ -112,7 +113,7 @@ public object Types {
public fun newParameterizedTypeWithOwner(
ownerType: Type?,
rawType: Type,
vararg typeArguments: Type
vararg typeArguments: Type,
): ParameterizedType {
require(typeArguments.isNotEmpty()) {
"Missing type arguments for $rawType"
@@ -198,7 +199,9 @@ public object Types {
}
return if (collectionType is ParameterizedType) {
collectionType.actualTypeArguments[0]
} else Any::class.java
} else {
Any::class.java
}
}
/** Returns true if `a` and `b` are equal. */
@@ -254,7 +257,7 @@ public object Types {
@JvmStatic
public fun getFieldJsonQualifierAnnotations(
clazz: Class<*>,
fieldName: String
fieldName: String,
): Set<Annotation> {
try {
val field = clazz.getDeclaredField(fieldName)
@@ -271,7 +274,8 @@ public object Types {
}
} catch (e: NoSuchFieldException) {
throw IllegalArgumentException(
"Could not access field $fieldName on class ${clazz.canonicalName}", e
"Could not access field $fieldName on class ${clazz.canonicalName}",
e,
)
}
}
@@ -289,7 +293,8 @@ public object Types {
}
@Suppress("UNCHECKED_CAST")
return Proxy.newProxyInstance(
annotationType.classLoader, arrayOf<Class<*>>(annotationType)
annotationType.classLoader,
arrayOf<Class<*>>(annotationType),
) { proxy, method, args ->
when (method.name) {
"annotationType" -> annotationType

View File

@@ -15,6 +15,7 @@
*/
@file:JvmName("Util")
@file:Suppress("unused", "MemberVisibilityCanBePrivate")
package com.squareup.moshi.internal
import com.squareup.moshi.Json
@@ -49,6 +50,7 @@ import java.util.LinkedHashSet
import kotlin.contracts.contract
@JvmField internal val NO_ANNOTATIONS: Set<Annotation> = emptySet()
@JvmField internal val EMPTY_TYPE_ARRAY: Array<Type> = arrayOf()
@Suppress("UNCHECKED_CAST")
@@ -108,7 +110,7 @@ public val Array<Annotation>.jsonAnnotations: Set<Annotation>
for (annotation in this) {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
if ((annotation as java.lang.annotation.Annotation).annotationType()
.isAnnotationPresent(JsonQualifier::class.java)
.isAnnotationPresent(JsonQualifier::class.java)
) {
if (result == null) result = LinkedHashSet()
result.add(annotation)
@@ -118,7 +120,7 @@ public val Array<Annotation>.jsonAnnotations: Set<Annotation>
}
internal fun Set<Annotation>.isAnnotationPresent(
annotationClass: Class<out Annotation>
annotationClass: Class<out Annotation>,
): Boolean {
if (isEmpty()) return false // Save an iterator in the common case.
for (annotation in this) {
@@ -207,7 +209,7 @@ public fun Type.resolve(context: Type, contextRawType: Class<*>): Type {
private fun Type.resolve(
context: Type,
contextRawType: Class<*>,
visitedTypeVariables: MutableCollection<TypeVariable<*>>
visitedTypeVariables: MutableCollection<TypeVariable<*>>,
): Type {
// This implementation is made a little more complicated in an attempt to avoid object-creation.
var toResolve = this
@@ -361,7 +363,7 @@ internal fun Type.toStringWithAnnotations(annotations: Set<Annotation>): String
*/
public fun Moshi.generatedAdapter(
type: Type,
rawType: Class<*>
rawType: Class<*>,
): JsonAdapter<*>? {
val jsonClass = rawType.getAnnotation(JsonClass::class.java)
if (jsonClass == null || !jsonClass.generateAdapter) {
@@ -403,11 +405,12 @@ public fun Moshi.generatedAdapter(
if (possiblyFoundAdapter != null && type !is ParameterizedType && possiblyFoundAdapter.typeParameters.isNotEmpty()) {
throw RuntimeException(
"Failed to find the generated JsonAdapter constructor for '$type'. Suspiciously, the type was not parameterized but the target class '${possiblyFoundAdapter.canonicalName}' is generic. Consider using Types#newParameterizedType() to define these missing type variables.",
e
e,
)
} else {
throw RuntimeException(
"Failed to find the generated JsonAdapter constructor for $type", e
"Failed to find the generated JsonAdapter constructor for $type",
e,
)
}
} catch (e: IllegalAccessException) {
@@ -452,7 +455,7 @@ private fun <T> Class<T>.findConstructor(): Constructor<T> {
public fun missingProperty(
propertyName: String?,
jsonName: String?,
reader: JsonReader
reader: JsonReader,
): JsonDataException {
val path = reader.path
val message = if (jsonName == propertyName) {
@@ -466,7 +469,7 @@ public fun missingProperty(
public fun unexpectedNull(
propertyName: String,
jsonName: String,
reader: JsonReader
reader: JsonReader,
): JsonDataException {
val path = reader.path
val message: String = if (jsonName == propertyName) {
@@ -512,7 +515,7 @@ internal class ParameterizedTypeImpl private constructor(
private val ownerType: Type?,
private val rawType: Type,
@JvmField
val typeArguments: Array<Type>
val typeArguments: Array<Type>,
) : ParameterizedType {
override fun getActualTypeArguments() = typeArguments.clone()
@@ -547,14 +550,16 @@ internal class ParameterizedTypeImpl private constructor(
operator fun invoke(
ownerType: Type?,
rawType: Type,
vararg typeArguments: Type
vararg typeArguments: Type,
): ParameterizedTypeImpl {
// Require an owner type if the raw type needs it.
if (rawType is Class<*>) {
val enclosingClass = rawType.enclosingClass
if (ownerType != null) {
require(!(enclosingClass == null || ownerType.rawType != enclosingClass)) { "unexpected owner type for $rawType: $ownerType" }
} else require(enclosingClass == null) { "unexpected owner type for $rawType: null" }
} else {
require(enclosingClass == null) { "unexpected owner type for $rawType: null" }
}
}
@Suppress("UNCHECKED_CAST")
val finalTypeArgs = typeArguments.clone() as Array<Type>
@@ -594,7 +599,7 @@ internal class GenericArrayTypeImpl private constructor(private val componentTyp
*/
internal class WildcardTypeImpl private constructor(
private val upperBound: Type,
private val lowerBound: Type?
private val lowerBound: Type?,
) : WildcardType {
override fun getUpperBounds() = arrayOf(upperBound)
@@ -622,7 +627,7 @@ internal class WildcardTypeImpl private constructor(
@JvmName("create")
operator fun invoke(
upperBounds: Array<Type>,
lowerBounds: Array<Type>
lowerBounds: Array<Type>,
): WildcardTypeImpl {
require(lowerBounds.size <= 1)
require(upperBounds.size == 1)
@@ -631,13 +636,13 @@ internal class WildcardTypeImpl private constructor(
require(!(upperBounds[0] !== Any::class.java))
WildcardTypeImpl(
lowerBound = lowerBounds[0].canonicalize(),
upperBound = Any::class.java
upperBound = Any::class.java,
)
} else {
upperBounds[0].checkNotPrimitive()
WildcardTypeImpl(
lowerBound = null,
upperBound = upperBounds[0].canonicalize()
upperBound = upperBounds[0].canonicalize(),
)
}
}

View File

@@ -37,14 +37,14 @@ import java.lang.reflect.Type
internal class RecordJsonAdapter<T>(
private val constructor: MethodHandle,
private val targetClass: String,
componentBindings: Map<String, ComponentBinding<Any>>
componentBindings: Map<String, ComponentBinding<Any>>,
) : JsonAdapter<T>() {
data class ComponentBinding<T>(
val componentName: String,
val jsonName: String,
val adapter: JsonAdapter<T>,
val accessor: MethodHandle
val accessor: MethodHandle,
)
private val componentBindingsArray = componentBindings.values.toTypedArray()
@@ -77,7 +77,7 @@ internal class RecordJsonAdapter<T>(
throw missingProperty(
propertyName = componentBindingsArray[i].componentName,
jsonName = componentBindingsArray[i].jsonName,
reader = reader
reader = reader,
)
}
}
@@ -133,7 +133,7 @@ internal class RecordJsonAdapter<T>(
val replaced = bindings.put(componentBinding.jsonName, componentBinding)
if (replaced != null) {
throw IllegalArgumentException(
"Conflicting components:\n ${replaced.componentName}\n ${componentBinding.componentName}"
"Conflicting components:\n ${replaced.componentName}\n ${componentBinding.componentName}",
)
}
component.type
@@ -155,7 +155,7 @@ internal class RecordJsonAdapter<T>(
rawType: Class<*>,
moshi: Moshi,
lookup: MethodHandles.Lookup,
component: RecordComponent
component: RecordComponent,
): ComponentBinding<Any> {
val componentName = component.name
val jsonName = component.jsonName(componentName)