Skip to content

Commit

Permalink
Update kotlin (and related dependencies) to 2.0.21.
Browse files Browse the repository at this point in the history
This CL also updates kotlin-metadata-jvm to 2.0.21 which requires migrating, since all of the deprecated methods Dagger/Hilt previously referenced were removed in v2.0.0.

Fixes #4525

RELNOTES=Fixes #4525: Update kotlin-jvm-metadata to 2.0.21 to remove dependency on Beta version.
PiperOrigin-RevId: 702486745
  • Loading branch information
bcorso authored and Dagger Team committed Dec 4, 2024
1 parent 369bbc6 commit b420311
Show file tree
Hide file tree
Showing 17 changed files with 247 additions and 504 deletions.
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ http_archive(

load("@io_bazel_rules_kotlin//kotlin:repositories.bzl", "kotlin_repositories", "kotlinc_version")

KOTLIN_VERSION = "1.9.24"
KOTLIN_VERSION = "2.0.21"

# Get from https://github.com/JetBrains/kotlin/releases/
KOTLINC_RELEASE_SHA = "eb7b68e01029fa67bc8d060ee54c12018f2c60ddc438cf21db14517229aa693b"
Expand Down Expand Up @@ -203,7 +203,7 @@ GRPC_VERSION = "1.2.0"

INCAP_VERSION = "0.2"

KSP_VERSION = KOTLIN_VERSION + "-1.0.20"
KSP_VERSION = KOTLIN_VERSION + "-1.0.28"

MAVEN_VERSION = "3.3.3"

Expand Down Expand Up @@ -291,7 +291,7 @@ maven_install(
"org.jetbrains.kotlin:kotlin-compiler-embeddable:%s" % KOTLIN_VERSION,
"org.jetbrains.kotlin:kotlin-daemon-embeddable:%s" % KOTLIN_VERSION,
"org.jetbrains.kotlin:kotlin-stdlib:%s" % KOTLIN_VERSION,
"org.jetbrains.kotlin:kotlin-metadata-jvm:2.0.0-Beta5",
"org.jetbrains.kotlin:kotlin-metadata-jvm:%s" % KOTLIN_VERSION,
"org.jspecify:jspecify:1.0.0",
"org.mockito:mockito-core:2.28.2",
"org.pantsbuild:jarjar:1.7.2",
Expand Down
4 changes: 2 additions & 2 deletions java/dagger/hilt/android/plugin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
buildscript {
ext {
kotlin_version = "1.9.24"
kotlin_version = "2.0.21"
agp_version = System.getenv('AGP_VERSION') ?: "8.1.1"
ksp_version = "$kotlin_version-1.0.20"
ksp_version = "$kotlin_version-1.0.28"
pluginArtifactId = 'hilt-android-gradle-plugin'
pluginId = 'com.google.dagger.hilt.android'
}
Expand Down
9 changes: 6 additions & 3 deletions java/dagger/hilt/processor/internal/kotlin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
# Description:
# Sources related to Kotlin metadata.

load("@rules_java//java:defs.bzl", "java_library")
load("@io_bazel_rules_kotlin//kotlin:jvm.bzl", "kt_jvm_library")

package(default_visibility = ["//:src"])

java_library(
kt_jvm_library(
name = "kotlin",
srcs = glob(["*.java"]),
srcs = glob([
"*.java",
"*.kt",
]),
deps = [
"//:dagger_with_compiler",
"//java/dagger/hilt/processor/internal:classnames",
Expand Down
102 changes: 102 additions & 0 deletions java/dagger/hilt/processor/internal/kotlin/ClassMetadata.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (C) 2023 The Dagger Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package dagger.hilt.processor.internal.kotlin

import androidx.room.compiler.processing.XAnnotation
import androidx.room.compiler.processing.XFieldElement
import androidx.room.compiler.processing.XMethodElement
import androidx.room.compiler.processing.XTypeElement
import kotlin.Metadata
import kotlin.metadata.declaresDefaultValue
import kotlin.metadata.KmClass
import kotlin.metadata.KmConstructor
import kotlin.metadata.KmFunction
import kotlin.metadata.KmProperty
import kotlin.metadata.KmValueParameter
import kotlin.metadata.jvm.KotlinClassMetadata
import kotlin.metadata.jvm.fieldSignature
import kotlin.metadata.jvm.getterSignature
import kotlin.metadata.jvm.signature
import kotlin.metadata.jvm.syntheticMethodForAnnotations

/** Container classes for kotlin metadata types. */
class ClassMetadata private constructor(private val kmClass: KmClass) {
val functionsBySignature = buildList<FunctionMetadata> {
addAll(kmClass.constructors.map { ConstructorMetadata(it) })
addAll(kmClass.functions.map { MethodMetadata(it) })
}.associate { it.signature to it }

val propertiesBySignature =
kmClass.properties
.map { PropertyMetadata(it) }
.associate { it.fieldSignature to it }
.filterKeys { it != null }

fun constructors(): List<FunctionMetadata> =
functionsBySignature.values
.filter { it is ConstructorMetadata }
.toList()

companion object {
/** Parse Kotlin class metadata from a given type element. */
@JvmStatic
fun of(typeElement: XTypeElement): ClassMetadata {
val metadataAnnotation = checkNotNull(typeElement.getAnnotation(Metadata::class)).value
return when (val classMetadata = KotlinClassMetadata.readStrict(metadataAnnotation)) {
is KotlinClassMetadata.Class -> ClassMetadata(classMetadata.kmClass)
else -> error("Unsupported metadata type: ${classMetadata}")
}
}
}
}

class ConstructorMetadata(private val kmConstructor: KmConstructor) : FunctionMetadata {
override val name = "<init>"
override val signature = kmConstructor.signature!!.toString()
override val parameters = kmConstructor.valueParameters.map { ParameterMetadata(it) }
}

class MethodMetadata(private val kmFunction: KmFunction) : FunctionMetadata {
override val name = kmFunction.name
override val signature = kmFunction.signature!!.toString()
override val parameters = kmFunction.valueParameters.map { ParameterMetadata(it) }
}

interface FunctionMetadata {
val name: String
val signature: String
val parameters: List<ParameterMetadata>
}

class PropertyMetadata(private val kmProperty: KmProperty) {
val name = kmProperty.name

/** Returns the JVM field descriptor of the backing field of this property. */
val fieldSignature = kmProperty.fieldSignature?.toString()

val getterSignature = kmProperty.getterSignature?.toString()

/** Returns JVM method descriptor of the synthetic method for property annotations. */
val methodForAnnotationsSignature = kmProperty.syntheticMethodForAnnotations?.toString()
}

class ParameterMetadata(private val kmValueParameter: KmValueParameter) {
val name = kmValueParameter.name

fun declaresDefaultValue() = kmValueParameter.declaresDefaultValue
}

Loading

0 comments on commit b420311

Please sign in to comment.