Skip to content

Commit

Permalink
Merge pull request #2261 from jsjeon/1.0.20-release-2.1.20-beta1
Browse files Browse the repository at this point in the history
Add support for Kotlin 2.1.20-Beta1
  • Loading branch information
mkmuir0 authored Dec 20, 2024
2 parents 08dbaa7 + 1ef8169 commit 7605f9b
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import com.intellij.psi.impl.source.PsiClassReferenceType
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
import org.jetbrains.kotlin.codegen.ClassBuilderMode
import org.jetbrains.kotlin.codegen.OwnerKind
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.container.ComponentProvider
Expand All @@ -66,9 +66,11 @@ import org.jetbrains.kotlin.container.tryGetService
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.load.java.components.TypeUsage
import org.jetbrains.kotlin.load.java.descriptors.JavaForKotlinOverridePropertyDescriptor
import org.jetbrains.kotlin.load.java.descriptors.getImplClassNameForDeserialized
import org.jetbrains.kotlin.load.java.lazy.*
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaTypeParameterDescriptor
import org.jetbrains.kotlin.load.java.lazy.types.JavaTypeResolver
Expand Down Expand Up @@ -106,13 +108,15 @@ import org.jetbrains.kotlin.resolve.multiplatform.findExpects
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
import org.jetbrains.kotlin.types.typeUtil.replaceArgumentsWithStarProjections
import org.jetbrains.kotlin.types.typeUtil.substitute
import org.jetbrains.kotlin.types.typeUtil.supertypes
import org.jetbrains.kotlin.util.containingNonLocalDeclaration
import org.jetbrains.org.objectweb.asm.Opcodes
import org.jetbrains.org.objectweb.asm.Type
import java.io.File
import java.util.*

Expand Down Expand Up @@ -356,20 +360,28 @@ class ResolverImpl(
override fun mapToJvmSignature(declaration: KSDeclaration): String? = mapToJvmSignatureInternal(declaration)

internal fun mapToJvmSignatureInternal(declaration: KSDeclaration): String? = when (declaration) {
is KSClassDeclaration -> resolveClassDeclaration(declaration)?.let { typeMapper.mapType(it).descriptor }
is KSClassDeclaration -> resolveClassDeclaration(declaration)?.let {
typeMapper.mapType(it.defaultType).descriptor
}
is KSFunctionDeclaration -> resolveFunctionDeclaration(declaration)?.let {
when (it) {
is FunctionDescriptor -> typeMapper.mapAsmMethod(it).descriptor
is PropertyDescriptor -> typeMapper.mapFieldSignature(it.type, it) ?: typeMapper.mapType(it).descriptor
is PropertyDescriptor -> typeMapper.mapPropertySignature(it)
else -> throw IllegalStateException("Unexpected descriptor type for declaration: $declaration")
}
}
is KSPropertyDeclaration -> resolvePropertyDeclaration(declaration)?.let {
typeMapper.mapFieldSignature(it.type, it) ?: typeMapper.mapType(it).descriptor
typeMapper.mapPropertySignature(it)
}
else -> null
}

private fun KotlinTypeMapper.mapPropertySignature(descriptor: PropertyDescriptor): String? {
val sw = BothSignatureWriter(BothSignatureWriter.Mode.TYPE)
writeFieldSignature(descriptor.type, descriptor, sw)
return sw.makeJavaGenericSignature() ?: mapType(descriptor.type).descriptor
}

override fun overrides(overrider: KSDeclaration, overridee: KSDeclaration): Boolean {
fun resolveForOverride(declaration: KSDeclaration): DeclarationDescriptor? {
return when (declaration) {
Expand Down Expand Up @@ -880,22 +892,13 @@ class ResolverImpl(

@KspExperimental
override fun getJvmName(accessor: KSPropertyAccessor): String? {
val descriptor = resolvePropertyAccessorDeclaration(accessor)

return descriptor?.let {
// KotlinTypeMapper.mapSignature always uses OwnerKind.IMPLEMENTATION
typeMapper.mapFunctionName(descriptor, OwnerKind.IMPLEMENTATION)
}
return resolvePropertyAccessorDeclaration(accessor)?.let(typeMapper::mapFunctionName)
}

@KspExperimental
override fun getJvmName(declaration: KSFunctionDeclaration): String? {
// function names might be mangled if they receive inline class parameters or they are internal
val descriptor = resolveFunctionDeclaration(declaration)
return (descriptor as? FunctionDescriptor)?.let {
// KotlinTypeMapper.mapSignature always uses OwnerKind.IMPLEMENTATION
typeMapper.mapFunctionName(it, OwnerKind.IMPLEMENTATION)
}
return (resolveFunctionDeclaration(declaration) as? FunctionDescriptor)?.let(typeMapper::mapFunctionName)
}

@KspExperimental
Expand All @@ -911,11 +914,35 @@ class ResolverImpl(
}

private fun getJvmOwnerQualifiedName(descriptor: DeclarationDescriptor): String? {
return try {
typeMapper.mapImplementationOwner(descriptor).className
} catch (unsupported: UnsupportedOperationException) {
null
return typeMapper.mapJvmImplementationOwner(descriptor)?.className
}

private fun KotlinTypeMapper.mapJvmImplementationOwner(descriptor: DeclarationDescriptor): Type? {
if (descriptor is ConstructorDescriptor) {
return mapClass(descriptor.constructedClass)
}

return when (val container = descriptor.containingDeclaration) {
is PackageFragmentDescriptor ->
internalNameForPackageMemberOwner(descriptor as CallableMemberDescriptor)?.let(Type::getObjectType)
is ClassDescriptor ->
mapClass(container)
else -> null
}
}

private fun internalNameForPackageMemberOwner(descriptor: CallableMemberDescriptor): String? {
val file = DescriptorToSourceUtils.getContainingFile(descriptor)
if (file != null) {
return JvmFileClassUtil.getFileClassInternalName(file)
}

val directMember = DescriptorUtils.getDirectMember(descriptor)
if (directMember is DescriptorWithContainerSource) {
return directMember.getImplClassNameForDeserialized()?.internalName
}

return null
}

// TODO: refactor and reuse BinaryClassInfoCache
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ abstract class AbstractKSPTest(frontend: FrontendKind<*>) : DisposableTest() {
"-classpath", classpath,
"-d", module.outDir.path
)
compileJavaFiles(javaFiles, options, assertions = JUnit5Assertions)
compileJavaFiles(javaFiles, options)
}

fun runTest(@TestDataFile path: String) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copied from kotlinc
org.gradle.jvmargs=-Duser.country=US -Dkotlin.daemon.jvm.options=-Xmx4096m -Dfile.encoding=UTF-8

kotlinBaseVersion=2.1.0
kotlinBaseVersion=2.1.20-Beta1
agpBaseVersion=7.3.1
agpTestVersion=8.7.1
intellijVersion=233.13135.128
Expand Down

0 comments on commit 7605f9b

Please sign in to comment.