Skip to content

Commit

Permalink
Fix resolving JVM signature for Java enum
Browse files Browse the repository at this point in the history
  • Loading branch information
dstepanov authored and neetopia committed Dec 13, 2023
1 parent 0f78417 commit ee8854e
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ class ResolverImpl(
is KSClassDeclarationImpl -> resolveDeclaration(classDeclaration.ktClassOrObject)
is KSClassDeclarationDescriptorImpl -> classDeclaration.descriptor
is KSClassDeclarationJavaImpl -> resolveJavaDeclaration(classDeclaration.psi)
is KSClassDeclarationJavaEnumEntryImpl -> resolveJavaDeclaration(classDeclaration.psi)
else -> throw IllegalStateException("unexpected class: ${classDeclaration.javaClass}")
} as ClassDescriptor?
}
Expand Down
67 changes: 67 additions & 0 deletions kotlin-analysis-api/testData/signatureMapper.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2020 Google LLC
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
*
* 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.
*/

// TEST PROCESSOR: MapSignatureProcessor
// EXPECTED:
// LCls;
// a: I
// foo: ()Ljava/lang/String;
// <init>: ()V
// LJavaIntefaceWithVoid;
// getVoid: ()Ljava/lang/Void;
// LJavaClass;
// <init>: ()V
// LJavaAnno;
// intParam: I
// <init>: (I)V
// LJavaEnum;
// VAL1: LJavaEnum;
// VAL2: LJavaEnum;
// DEFAULT: LJavaEnum;
// values: ()[LJavaEnum;
// valueOf: (Ljava/lang/String;)LJavaEnum;
// entries: Lkotlin/enums/EnumEntries;
// END

// FILE: Cls.kt
class Cls {
val a: Int = 1

fun foo(): String { return "1" }
}

// FILE: JavaIntefaceWithVoid.java
interface JavaIntefaceWithVoid {
Void getVoid();
}

// FILE: JavaClass.java
class JavaClass {
JavaClass() {}
}

// FILE: JavaAnno.java
@interface JavaAnno {
int intParam();
}

// FILE: JavaEnum.java
public enum JavaEnum {
VAL1,
VAL2,
DEFAULT
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MapSignatureProcessor : AbstractTestProcessor() {
}

override fun process(resolver: Resolver): List<KSAnnotated> {
listOf("Cls", "JavaIntefaceWithVoid", "JavaClass", "JavaAnno")
listOf("Cls", "JavaIntefaceWithVoid", "JavaClass", "JavaAnno", "JavaEnum")
.map { className ->
resolver.getClassDeclarationByName(className)!!
}.forEach { subject ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ class KSPAATest : AbstractKSPAATest() {
@TestMetadata("signatureMapper.kt")
@Test
fun testSignatureMapper() {
runTest("../test-utils/testData/api/signatureMapper.kt")
runTest("../kotlin-analysis-api/testData/signatureMapper.kt")
}

@TestMetadata("superTypes.kt")
Expand Down
14 changes: 14 additions & 0 deletions test-utils/testData/api/signatureMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
// LJavaAnno;
// intParam: I
// <init>: (I)V
// LJavaEnum;
// VAL1: LJavaEnum;
// VAL2: LJavaEnum;
// DEFAULT: LJavaEnum;
// values: ()[LJavaEnum;
// valueOf: (Ljava/lang/String;)LJavaEnum;
// <init>: (Ljava/lang/String;I)V
// END

// FILE: Cls.kt
Expand All @@ -51,3 +58,10 @@ class JavaClass {
@interface JavaAnno {
int intParam();
}

// FILE: JavaEnum.java
public enum JavaEnum {
VAL1,
VAL2,
DEFAULT
}

0 comments on commit ee8854e

Please sign in to comment.