Skip to content

Commit

Permalink
Update to Kotlin 1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
alexvanyo committed Apr 6, 2023
1 parent 9002878 commit 2ed6d49
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 691 deletions.
661 changes: 0 additions & 661 deletions config/detekt/detekt.yml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
autoService = "1.0"
detekt = "1.20.0"
dokka = "1.7.0"
detekt = "1.22.0"
dokka = "1.8.10"
incap = "0.3"
jacoco = "0.8.7"
jacoco = "0.8.8"
junit = "5.8.1"
kotlin = "1.7.0"
kotlinxBinaryCompatibilityValidator = "0.11.0"
kotlinCompileTesting = "1.4.9"
kotlinPoet = "1.12.0"
ksp = "1.7.0-1.0.6"
kotlin = "1.8.0"
kotlinxBinaryCompatibilityValidator = "0.13.0"
kotlinCompileTesting = "1.5.0"
kotlinPoet = "1.13.0"
ksp = "1.8.0-1.0.9"

[libraries]
autoService-runtime = { module = "com.google.auto.service:auto-service-annotations", version.ref = "autoService" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public data class GenSealedEnumHolder(
it.name?.asString() == "traversalOrder"
}?.value.toString()

@Suppress("SwallowedException")
val traversalOrder = try {
@Suppress("UnsafeCallOnNullableType")
TreeTraversalOrder.valueOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ internal class SealedEnumProcessor(
resolver: Resolver,
sealedClassCompanionObjectKSClass: KSClassDeclaration
): SealedEnumFileSpec? {

val genSealedEnumClassType = getGenSealedEnumClassDeclaration(resolver).asType()

/**
Expand Down Expand Up @@ -231,7 +230,7 @@ internal class SealedEnumProcessor(
}
// Second, order by the qualified name
.thenComparing { classDeclaration ->
classDeclaration.qualifiedName?.asString() ?: ""
classDeclaration.qualifiedName?.asString().orEmpty()
}
)
.map(::convertSealedSubclassToNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ internal class SuperInterfaces(
.filter {
val declaration = it.declaration
declaration is KSClassDeclaration &&
declaration.classKind == ClassKind.INTERFACE &&
declaration.isVisibleInterface() &&
!declaration.isSealedInterface()
declaration.classKind == ClassKind.INTERFACE &&
declaration.isVisibleInterface() &&
!declaration.isSealedInterface()
}
.map { it.substituteTypeNames(typeVariableNamesToTypeArguments) }
.filter { it.isValidInterface() }
Expand Down Expand Up @@ -103,7 +103,7 @@ internal class SuperInterfaces(
*/
private fun KSClassDeclaration.isVisibleInterface(): Boolean =
isPublic() || isInternal() || isJavaPackagePrivate() ||
(isProtected() && origin == Origin.JAVA && packageName == sealedEnumKSClass.packageName)
(isProtected() && origin == Origin.JAVA && packageName == sealedEnumKSClass.packageName)

/**
* Returns true if the [KSClassDeclaration] interface is sealed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.TypeName
import javax.lang.model.element.TypeElement

internal data class SealedEnumEnumPropertySpec(
private val sealedClass: SealedClass,
private val sealedClassVisibility: Visibility,
private val parameterizedSealedClass: TypeName,
private val sealedClassCompanionObjectElement: TypeElement?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ public data class SealedEnumFileSpec(
// Add the SealedClass.enum extension property
fileSpecBuilder.addProperty(
SealedEnumEnumPropertySpec(
sealedClass = sealedClass,
sealedClassVisibility = sealedClassVisibility,
parameterizedSealedClass = parameterizedSealedClass,
sealedClassCompanionObjectElement = sealedClassCompanionObjectElement,
Expand Down Expand Up @@ -177,7 +176,6 @@ public data class SealedEnumFileSpec(
// Add the SealedEnum.ordinal extension property
fileSpecBuilder.addProperty(
SealedEnumOrdinalPropertySpec(
sealedClass = sealedClass,
sealedClassVisibility = sealedClassVisibility,
parameterizedSealedClass = parameterizedSealedClass,
sealedClassCompanionObjectElement = sealedClassCompanionObjectElement,
Expand All @@ -190,7 +188,6 @@ public data class SealedEnumFileSpec(
// Add the SealedEnum.name extension property
fileSpecBuilder.addProperty(
SealedEnumNamePropertySpec(
sealedClass = sealedClass,
sealedClassVisibility = sealedClassVisibility,
parameterizedSealedClass = parameterizedSealedClass,
sealedClassCompanionObjectElement = sealedClassCompanionObjectElement,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.TypeName
import javax.lang.model.element.TypeElement

internal data class SealedEnumNamePropertySpec(
private val sealedClass: SealedClass,
private val sealedClassVisibility: Visibility,
private val parameterizedSealedClass: TypeName,
private val sealedClassCompanionObjectElement: TypeElement?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import com.squareup.kotlinpoet.TypeName
import javax.lang.model.element.TypeElement

internal data class SealedEnumOrdinalPropertySpec(
private val sealedClass: SealedClass,
private val sealedClassVisibility: Visibility,
private val parameterizedSealedClass: TypeName,
private val sealedClassCompanionObjectElement: TypeElement?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ class ProtectedInterfaceSealedClassTests {
@Test
fun `sealed class has correct enum values with mapping`() {
assertEquals(
ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.values.map(ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass::enum),
ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass.values.map(
ProtectedInterfaceOuterClass.ProtectedInterfaceSealedClass::enum
),
enumValues<ProtectedInterfaceOuterClass_ProtectedInterfaceSealedClassEnum>().toList()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests {
@Test
fun `sealed class has correct enum values with mapping`() {
assertEquals(
ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.values.map(ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass::enum),
ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass.values.map(
ProtectedInterfaceOuterClassWithDifferentPackageBaseClass.ProtectedInterfaceSealedClass::enum
),
enumValues<ProtectedInterfaceOuterClassWithDifferentPackageBaseClass_ProtectedInterfaceSealedClassEnum>().toList()
)
}
Expand All @@ -50,7 +52,11 @@ class ProtectedInterfaceSealedClassWithDifferentPackageBaseClassTests {
@Test
fun `compilation generates correct code`() {
val result = compile(
getCommonSourceFile("compilation", "visibility", "ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt")
getCommonSourceFile(
"compilation",
"visibility",
"ProtectedInterfaceSealedClassWithDifferentPackageBaseClass.kt"
)
)

assertCompiles(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class SealedEnumProcessor : AbstractProcessor() {
*/
@Suppress("ReturnCount", "LongMethod", "ComplexMethod")
private fun createSealedEnumFileSpec(sealedClassCompanionObjectElement: TypeElement): SealedEnumFileSpec? {

/**
* A helper function to print the given [message] as an error.
*/
Expand All @@ -106,7 +105,7 @@ public class SealedEnumProcessor : AbstractProcessor() {
* The [KmClass] for the sealed class's companion object.
*/
val sealedClassCompanionObjectKmClass =
@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
try {
sealedClassCompanionObjectElement.toKmClass()
} catch (exception: Exception) {
Expand Down Expand Up @@ -134,7 +133,7 @@ public class SealedEnumProcessor : AbstractProcessor() {
* The [KmClass] for the sealed class.
*/
val sealedClassKmClass =
@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
try {
(sealedClassElement as TypeElement).toKmClass()
} catch (exception: Exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ internal class SuperInterfaces(
) {
check(typeElement.typeParameters.size == parentTypeArguments.size)

@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
try {
val typeSpec = typeElement.toTypeSpec(classInspector)
getAllSuperInterfacesKotlinImpl(typeElement, typeSpec, parentTypeArguments, superInterfaces)
Expand Down Expand Up @@ -194,7 +194,7 @@ internal class SuperInterfaces(
return STAR
}

@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
val className = try {
createClassName(element.toKmClass().name)
} catch (exception: Exception) {
Expand All @@ -214,7 +214,7 @@ internal class SuperInterfaces(
/**
* Returns true if the [TypeElement] interface has the correct visibility to be implemented by a generated enum.
*/
@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
private fun TypeElement.isVisibleInterface(): Boolean =
try {
// If interface is a Kotlin interface
Expand All @@ -229,7 +229,7 @@ internal class SuperInterfaces(
/**
* Returns true if the [TypeElement] interface is a sealed interface.
*/
@Suppress("TooGenericExceptionCaught")
@Suppress("TooGenericExceptionCaught", "SwallowedException")
private fun TypeElement.isSealedInterface(): Boolean =
try {
// If interface is a Kotlin interface
Expand Down

0 comments on commit 2ed6d49

Please sign in to comment.