Skip to content
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
9 changes: 6 additions & 3 deletions api/src/main/kotlin/se/ansman/kotshi/KotshiUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,11 @@ object KotshiUtils {
override fun invoke(proxy: Any, method: Method, args: Array<out Any>?): 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 ->
Expand Down Expand Up @@ -261,4 +264,4 @@ object KotshiUtils {
throw JsonDataException("Expected $typeMessage but was $it at path $path")
}
}
}
}
13 changes: 7 additions & 6 deletions compiler/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -488,22 +488,22 @@ 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
},
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)
},
Expand Down Expand Up @@ -642,4 +642,4 @@ private fun AsmType.toReflectionString(): String =
// Object type
else -> className
}
}
}
8 changes: 7 additions & 1 deletion gradle-plugin/src/main/kotlin/library.gradle.kts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,11 +21,11 @@ extensions.configure<JavaPluginExtension> {
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",
)
Expand Down Expand Up @@ -73,3 +75,7 @@ configurations.configureEach {
}
}
}

configurations.matching { it.name == "testCompileClasspath" || it.name == "testRuntimeClasspath" }.configureEach {
attributes.attribute(TargetJvmVersion.TARGET_JVM_VERSION_ATTRIBUTE, 21)
}
7 changes: 5 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }

Expand All @@ -40,11 +40,14 @@ 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" }
ksp-aaEmbeddable = { module = "com.google.devtools.ksp:symbol-processing-aa-embeddable", version.ref = "ksp" }

asm = "org.ow2.asm:asm:9.9.1"

gradleMavenPublish = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin:0.36.0"
gradleMavenPublish = "com.vanniktech.maven.publish:com.vanniktech.maven.publish.gradle.plugin:0.36.0"
Original file line number Diff line number Diff line change
Expand Up @@ -602,4 +602,4 @@ abstract class BaseGeneratorTest {
.first { it.name == name }
.readText()
.trim()
}
}
Loading