forked from square/dagger
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update kotlin (and related dependencies) to 2.0.21.
This CL: * Updates KSP to 2.0.21-1.0.28 * Updates kotlin-metadata-jvm to 2.0.21 * Note: due to bazelbuild/rules_kotlin#1176 we can't actually update Kotlin itself to 2.0.21, but somehow that doesn't seem to cause an issue * Migrates kotlin-metadata-jvm usages to the new API (the pre-2.0.0 APIs are deprecated). * Updates XProcessing and XProcessing Testing jars * Adds flags to fall back to Kotlin 1.9 for compiler tests (Working on getting these tests working with K2/KSP2 is in progress). * Updated all of our artifact tests to use the same Kotlin and KSP versions. * Added `compat_kt_jvm_library` to alias output jars to the expected locations. Fixes #4525 RELNOTES=Fixes #4525: Update kotlin-jvm-metadata to 2.0.21 to remove dependency on Beta version. PiperOrigin-RevId: 703516835
- Loading branch information
Showing
26 changed files
with
378 additions
and
600 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
java/dagger/hilt/processor/internal/kotlin/ClassMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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) }) | ||
}.associateBy { it.signature } | ||
|
||
val propertiesBySignature = | ||
kmClass.properties | ||
.filter { it.fieldSignature != null } | ||
.map { PropertyMetadata(it) } | ||
.associateBy { it.fieldSignature } | ||
|
||
fun constructors(): List<FunctionMetadata> = | ||
functionsBySignature.values.filterIsInstance<ConstructorMetadata>() | ||
|
||
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 | ||
} | ||
|
Oops, something went wrong.