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

Update dependency com.pinterest.ktlint:ktlint-cli to v1.4.1 #1901

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length=100

[*.{kt, kts}]
kotlin_imports_layout = ascii
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ class JsonStringJsonAdapterFactory : JsonAdapter.Factory {
}

private class JsonStringJsonAdapter : JsonAdapter<String>() {
override fun fromJson(reader: JsonReader): String =
reader.nextSource().use(BufferedSource::readUtf8)
override fun fromJson(reader: JsonReader): String = reader.nextSource().use(BufferedSource::readUtf8)

override fun toJson(writer: JsonWriter, value: String?) {
writer.valueSink().use { sink -> sink.writeUtf8(checkNotNull(value)) }
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ kotlinCompileTesting = { module = "dev.zacsweers.kctfork:core", version.ref = "k
kotlinCompileTesting-ksp = { module = "dev.zacsweers.kctfork:ksp", version.ref ="kotlinCompileTesting" }
truth = "com.google.truth:truth:1.4.4"
googleJavaFormat = "com.google.googlejavaformat:google-java-format:1.24.0"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.3.1"
ktlint = "com.pinterest.ktlint:ktlint-cli:1.4.1"
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,18 @@ internal fun TypeName.findRawType(): ClassName? {
}
}

internal fun TypeName.defaultPrimitiveValue(): CodeBlock =
when (this) {
BOOLEAN -> CodeBlock.of("false")
CHAR -> CodeBlock.of("0.toChar()")
BYTE -> CodeBlock.of("0.toByte()")
SHORT -> CodeBlock.of("0.toShort()")
INT -> CodeBlock.of("0")
FLOAT -> CodeBlock.of("0f")
LONG -> CodeBlock.of("0L")
DOUBLE -> CodeBlock.of("0.0")
UNIT, Void::class.asTypeName(), NOTHING -> throw IllegalStateException("Parameter with void, Unit, or Nothing type is illegal")
else -> CodeBlock.of("null")
}
internal fun TypeName.defaultPrimitiveValue(): CodeBlock = when (this) {
BOOLEAN -> CodeBlock.of("false")
CHAR -> CodeBlock.of("0.toChar()")
BYTE -> CodeBlock.of("0.toByte()")
SHORT -> CodeBlock.of("0.toShort()")
INT -> CodeBlock.of("0")
FLOAT -> CodeBlock.of("0f")
LONG -> CodeBlock.of("0L")
DOUBLE -> CodeBlock.of("0.0")
UNIT, Void::class.asTypeName(), NOTHING -> throw IllegalStateException("Parameter with void, Unit, or Nothing type is illegal")
else -> CodeBlock.of("null")
}

@OptIn(DelicateKotlinPoetApi::class)
internal fun TypeName.asTypeBlock(): CodeBlock {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ import kotlin.reflect.KClass
* @param name fully qualified name of the class to be loaded; using '.' as separator.
* @return a KSClassDeclaration, or null if not found.
*/
internal fun Resolver.getClassDeclarationByName(name: String): KSClassDeclaration? =
getClassDeclarationByName(getKSNameFromString(name))
internal fun Resolver.getClassDeclarationByName(name: String): KSClassDeclaration? = getClassDeclarationByName(getKSNameFromString(name))

internal fun <T : Annotation> KSAnnotated.getAnnotationsByType(annotationKClass: KClass<T>): Sequence<T> {
return this.annotations.filter {
Expand All @@ -49,8 +48,7 @@ internal fun <T : Annotation> KSAnnotated.getAnnotationsByType(annotationKClass:
}.map { it.toAnnotation(annotationKClass.java) }
}

internal fun <T : Annotation> KSAnnotated.isAnnotationPresent(annotationKClass: KClass<T>): Boolean =
getAnnotationsByType(annotationKClass).firstOrNull() != null
internal fun <T : Annotation> KSAnnotated.isAnnotationPresent(annotationKClass: KClass<T>): Boolean = getAnnotationsByType(annotationKClass).firstOrNull() != null

@Suppress("UNCHECKED_CAST")
private fun <T : Annotation> KSAnnotation.toAnnotation(annotationClass: Class<T>): T {
Expand Down Expand Up @@ -134,46 +132,45 @@ private fun KSAnnotation.asAnnotation(
}

@Suppress("UNCHECKED_CAST")
private fun List<*>.asArray(method: Method) =
when (method.returnType.componentType.name) {
"boolean" -> (this as List<Boolean>).toBooleanArray()
private fun List<*>.asArray(method: Method) = when (method.returnType.componentType.name) {
"boolean" -> (this as List<Boolean>).toBooleanArray()

"byte" -> (this as List<Byte>).toByteArray()
"byte" -> (this as List<Byte>).toByteArray()

"short" -> (this as List<Short>).toShortArray()
"short" -> (this as List<Short>).toShortArray()

"char" -> (this as List<Char>).toCharArray()
"char" -> (this as List<Char>).toCharArray()

"double" -> (this as List<Double>).toDoubleArray()
"double" -> (this as List<Double>).toDoubleArray()

"float" -> (this as List<Float>).toFloatArray()
"float" -> (this as List<Float>).toFloatArray()

"int" -> (this as List<Int>).toIntArray()
"int" -> (this as List<Int>).toIntArray()

"long" -> (this as List<Long>).toLongArray()
"long" -> (this as List<Long>).toLongArray()

"java.lang.Class" -> (this as List<KSType>).map {
Class.forName(it.declaration.qualifiedName!!.asString())
}.toTypedArray()
"java.lang.Class" -> (this as List<KSType>).map {
Class.forName(it.declaration.qualifiedName!!.asString())
}.toTypedArray()

"java.lang.String" -> (this as List<String>).toTypedArray()
"java.lang.String" -> (this as List<String>).toTypedArray()

else -> { // arrays of enums or annotations
when {
method.returnType.componentType.isEnum -> {
this.toArray(method) { result -> result.asEnum(method.returnType.componentType) }
}
else -> { // arrays of enums or annotations
when {
method.returnType.componentType.isEnum -> {
this.toArray(method) { result -> result.asEnum(method.returnType.componentType) }
}

method.returnType.componentType.isAnnotation -> {
this.toArray(method) { result ->
(result as KSAnnotation).asAnnotation(method.returnType.componentType)
}
method.returnType.componentType.isAnnotation -> {
this.toArray(method) { result ->
(result as KSAnnotation).asAnnotation(method.returnType.componentType)
}

else -> throw IllegalStateException("Unable to process type ${method.returnType.componentType.name}")
}

else -> throw IllegalStateException("Unable to process type ${method.returnType.componentType.name}")
}
}
}

@Suppress("UNCHECKED_CAST")
private fun List<*>.toArray(method: Method, valueProvider: (Any) -> Any): Array<Any?> {
Expand All @@ -188,17 +185,16 @@ private fun List<*>.toArray(method: Method, valueProvider: (Any) -> Any): Array<
}

@Suppress("UNCHECKED_CAST")
private fun <T> Any.asEnum(returnType: Class<T>): T =
returnType.getDeclaredMethod("valueOf", String::class.java)
.invoke(
null,
// Change from upstream KSP - https://github.com/google/ksp/pull/685
if (this is KSType) {
this.declaration.simpleName.getShortName()
} else {
this.toString()
},
) as T
private fun <T> Any.asEnum(returnType: Class<T>): T = returnType.getDeclaredMethod("valueOf", String::class.java)
.invoke(
null,
// Change from upstream KSP - https://github.com/google/ksp/pull/685
if (this is KSType) {
this.declaration.simpleName.getShortName()
} else {
this.toString()
},
) as T

private fun Any.asByte(): Byte = if (this is Int) this.toByte() else this as Byte

Expand Down
9 changes: 3 additions & 6 deletions moshi/src/main/java/com/squareup/moshi/Moshi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public class Moshi internal constructor(builder: Builder) {
public fun <T> adapter(type: Class<T>): JsonAdapter<T> = adapter(type, NO_ANNOTATIONS)

@CheckReturnValue
public fun <T> adapter(type: Type, annotationType: Class<out Annotation>): JsonAdapter<T> =
adapter(type, setOf(createJsonQualifierImplementation(annotationType)))
public fun <T> adapter(type: Type, annotationType: Class<out Annotation>): JsonAdapter<T> = adapter(type, setOf(createJsonQualifierImplementation(annotationType)))

@CheckReturnValue
public fun <T> adapter(type: Type, vararg annotationTypes: Class<out Annotation>): JsonAdapter<T> {
Expand All @@ -70,8 +69,7 @@ public class Moshi internal constructor(builder: Builder) {
}

@CheckReturnValue
public fun <T> adapter(type: Type, annotations: Set<Annotation>): JsonAdapter<T> =
adapter(type, annotations, fieldName = null)
public fun <T> adapter(type: Type, annotations: Set<Annotation>): JsonAdapter<T> = adapter(type, annotations, fieldName = null)

/**
* @return a [JsonAdapter] for [T], creating it if necessary. Note that while nullability of [T]
Expand Down Expand Up @@ -354,8 +352,7 @@ public class Moshi internal constructor(builder: Builder) {

override fun toJson(writer: JsonWriter, value: T?) = withAdapter { toJson(writer, value) }

private inline fun <R> withAdapter(body: JsonAdapter<T>.() -> R): R =
checkNotNull(adapter) { "JsonAdapter isn't ready" }.body()
private inline fun <R> withAdapter(body: JsonAdapter<T>.() -> R): R = checkNotNull(adapter) { "JsonAdapter isn't ready" }.body()

override fun toString() = adapter?.toString() ?: super.toString()
}
Expand Down
6 changes: 2 additions & 4 deletions moshi/src/main/java/com/squareup/moshi/internal/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -533,8 +533,7 @@ internal class ParameterizedTypeImpl private constructor(
override fun getOwnerType() = ownerType

@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
override fun equals(other: Any?) =
other is ParameterizedType && Types.equals(this, other as ParameterizedType?)
override fun equals(other: Any?) = other is ParameterizedType && Types.equals(this, other as ParameterizedType?)

override fun hashCode(): Int {
return typeArguments.contentHashCode() xor rawType.hashCode() xor ownerType.hashCodeOrZero
Expand Down Expand Up @@ -585,8 +584,7 @@ internal class GenericArrayTypeImpl private constructor(private val componentTyp
override fun getGenericComponentType() = componentType

@Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS")
override fun equals(other: Any?) =
other is GenericArrayType && Types.equals(this, other as GenericArrayType?)
override fun equals(other: Any?) = other is GenericArrayType && Types.equals(this, other as GenericArrayType?)

override fun hashCode() = componentType.hashCode()

Expand Down
Loading