diff --git a/api/src/main/kotlin/se/ansman/kotshi/KotshiUtils.kt b/api/src/main/kotlin/se/ansman/kotshi/KotshiUtils.kt index 30c9c8bd..c8820bb4 100644 --- a/api/src/main/kotlin/se/ansman/kotshi/KotshiUtils.kt +++ b/api/src/main/kotlin/se/ansman/kotshi/KotshiUtils.kt @@ -138,8 +138,11 @@ object KotshiUtils { override fun invoke(proxy: Any, method: Method, args: Array?): Any = when (method.name) { "annotationType" -> this@createJsonQualifierImplementation - "equals" -> args!![0] === proxy || isInstance(args!![0]) && annotationMethods.all { m -> - annotationValuesEquals(m.invoke(args[0]), annotationArguments[m.name] ?: m.defaultValue) + "equals" -> { + val other = args?.get(0) + other === proxy || isInstance(other) && annotationMethods.all { m -> + annotationValuesEquals(m.invoke(other), annotationArguments[m.name] ?: m.defaultValue) + } } // For the implementation see https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/annotation/Annotation.html#hashCode() "hashCode" -> annotationMethods.sumOf { m -> @@ -261,4 +264,4 @@ object KotshiUtils { throw JsonDataException("Expected $typeMessage but was $it at path $path") } } -} \ No newline at end of file +} diff --git a/compiler/build.gradle.kts b/compiler/build.gradle.kts index a6d17f38..e905d209 100644 --- a/compiler/build.gradle.kts +++ b/compiler/build.gradle.kts @@ -4,16 +4,17 @@ plugins { } dependencies { - compileOnly(libs.auto.service.api) - compileOnly(libs.ksp.api) - implementation(projects.api) + implementation(libs.auto.service.api) + kapt(libs.auto.service.compiler) + implementation(libs.incap.api) + kapt(libs.incap.compiler) + implementation(libs.auto.common) implementation(libs.kotlinpoet.core) implementation(libs.kotlinpoet.metadata) implementation(libs.kotlinpoet.ksp) implementation(libs.kotlin.metadata) implementation(libs.oldestSupportedMoshi) + implementation(libs.ksp.api) implementation(libs.asm) - - kapt(libs.auto.service.compiler) -} \ No newline at end of file +} diff --git a/compiler/src/main/kotlin/se/ansman/kotshi/renderer/DataClassAdapterRenderer.kt b/compiler/src/main/kotlin/se/ansman/kotshi/renderer/DataClassAdapterRenderer.kt index 8a9eb1d9..7cd77c98 100644 --- a/compiler/src/main/kotlin/se/ansman/kotshi/renderer/DataClassAdapterRenderer.kt +++ b/compiler/src/main/kotlin/se/ansman/kotshi/renderer/DataClassAdapterRenderer.kt @@ -348,7 +348,7 @@ class DataClassAdapterRenderer( if (hasDefaultValueConstructor) { val allMasksAreSetBlock = maskNames.withIndex() .map { (index, maskName) -> - CodeBlock.of("$maskName·== 0x${Integer.toHexString(maskAllSetValues[index])}.toInt()") + CodeBlock.of("$maskName·== %L", maskAllSetValues[index]) } .joinToCode("·&& ") beginControlFlow("if (%L)", allMasksAreSetBlock) @@ -488,7 +488,7 @@ class DataClassAdapterRenderer( } else if (hasDefaultValue) { CodeBlock.builder() .add("// \$mask = \$mask and (1 shl %L).inv()\n", maskIndex) - .addStatement("%1L = %1L and 0x%2L.toInt()", maskName, Integer.toHexString(mask.inv())) + .addStatement("%1L = %1L and %2L", maskName, mask.inv()) .build() } else { null @@ -496,14 +496,14 @@ class DataClassAdapterRenderer( isSet = if (localIsSet != null) { CodeBlock.of("%N", localIsSet) } else if (hasDefaultValue) { - CodeBlock.of("%1L and 0x%2L.toInt() != 0", maskName, Integer.toHexString(mask)) + CodeBlock.of("%1L and %2L != 0", maskName, mask) } else { CodeBlock.of("%N != null", value) }, isNotSet = if (localIsSet != null) { CodeBlock.of("!%N", localIsSet) } else if (hasDefaultValue) { - CodeBlock.of("%1L and 0x%2L.toInt() == 0", maskName, Integer.toHexString(mask)) + CodeBlock.of("%1L and %2L == 0", maskName, mask) } else { CodeBlock.of("%N == null", value) }, @@ -642,4 +642,4 @@ private fun AsmType.toReflectionString(): String = // Object type else -> className } - } \ No newline at end of file + } diff --git a/gradle-plugin/src/main/kotlin/library.gradle.kts b/gradle-plugin/src/main/kotlin/library.gradle.kts index 6a34aa76..1a38fead 100644 --- a/gradle-plugin/src/main/kotlin/library.gradle.kts +++ b/gradle-plugin/src/main/kotlin/library.gradle.kts @@ -1,5 +1,7 @@ import org.gradle.accessors.dm.LibrariesForLibs +import org.gradle.api.attributes.java.TargetJvmVersion +import org.jetbrains.kotlin.gradle.dsl.JvmDefaultMode import org.jetbrains.kotlin.gradle.dsl.JvmTarget plugins { @@ -19,11 +21,11 @@ extensions.configure { kotlin { compilerOptions { jvmTarget.set(JvmTarget.JVM_1_8) + jvmDefault.set(JvmDefaultMode.NO_COMPATIBILITY) allWarningsAsErrors.set(true) freeCompilerArgs.addAll( "-Xsuppress-version-warnings", "-opt-in=kotlin.RequiresOptIn", - "-Xjvm-default=all", "-Xcontext-parameters", "-Xannotation-default-target=param-property", ) @@ -73,3 +75,7 @@ configurations.configureEach { } } } + +configurations.matching { it.name == "testCompileClasspath" || it.name == "testRuntimeClasspath" }.configureEach { + attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21) +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f3b3e9a9..f9780c3b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -27,7 +27,7 @@ kotlinpoet-core = { module = "com.squareup:kotlinpoet", version.ref = "kotlinpoe kotlinpoet-metadata = { module = "com.squareup:kotlinpoet-metadata", version.ref = "kotlinpoet" } kotlinpoet-ksp = { module = "com.squareup:kotlinpoet-ksp", version.ref = "kotlinpoet" } -junit-bom = "org.junit:junit-bom:5.13.4" +junit-bom = "org.junit:junit-bom:6.0.3" junit-jupiter = { module = "org.junit.jupiter:junit-jupiter" } junit-platform-launcher = { module = "org.junit.platform:junit-platform-launcher" } @@ -40,6 +40,9 @@ moshi-latest = { module = "com.squareup.moshi:moshi", version.ref = "moshi-lates findBugs = "com.google.code.findbugs:jsr305:3.0.2" +incap-api = { module = "net.ltgt.gradle.incap:incap", version.ref = "incap" } +incap-compiler = { module = "net.ltgt.gradle.incap:incap-processor", version.ref = "incap" } + ksp = { module = "com.google.devtools.ksp:symbol-processing", version.ref = "ksp" } ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" } ksp-commonDeps = { module = "com.google.devtools.ksp:symbol-processing-common-deps", version.ref = "ksp" } @@ -47,4 +50,4 @@ ksp-aaEmbeddable = { module = "com.google.devtools.ksp:symbol-processing-aa-embe asm = "org.ow2.asm:asm:9.9.1" -gradleMavenPublish = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin:0.36.0" \ No newline at end of file +gradleMavenPublish = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin:0.36.0" diff --git a/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt b/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt index d006d1ec..930bf930 100644 --- a/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt +++ b/tests/src/test/kotlin/se/ansman/kotshi/BaseGeneratorTest.kt @@ -602,4 +602,4 @@ abstract class BaseGeneratorTest { .first { it.name == name } .readText() .trim() -} \ No newline at end of file +}