Skip to content

Commit e9efa37

Browse files
ting-yuanKSP Auto Pick
authored andcommitted
Handle a weird case from Analysis API
See #2480 for details. (cherry picked from commit 4bad3ba)
1 parent 0f5ff31 commit e9efa37

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/KSFunctionDeclarationImpl.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ class KSFunctionDeclarationImpl private constructor(internal val ktFunctionSymbo
139139
override val simpleName: KSName by lazy {
140140
when (ktFunctionSymbol) {
141141
is KaNamedFunctionSymbol -> KSNameImpl.getCached(ktFunctionSymbol.name.asString())
142-
is KaPropertyAccessorSymbol -> KSNameImpl.getCached((ktFunctionSymbol.psi as PsiMethod).name)
142+
is KaPropertyAccessorSymbol -> when (val psi = ktFunctionSymbol.psi) {
143+
is PsiMethod -> KSNameImpl.getCached(psi.name)
144+
else -> KSNameImpl.getCached(ktFunctionSymbol.callableId?.callableName?.asString() ?: "<no name>")
145+
}
143146
is KaConstructorSymbol -> KSNameImpl.getCached("<init>")
144147
else -> throw IllegalStateException("Unexpected function symbol type ${ktFunctionSymbol.javaClass}")
145148
}

kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ internal inline fun <R> analyze(crossinline action: KaSession.() -> R): R {
251251
return analyze(ResolverAAImpl.ktModule, action)
252252
}
253253

254+
// FIXME: https://github.com/google/ksp/issues/2480
254255
internal fun KaDeclarationContainerSymbol.declarations(): Sequence<KSDeclaration> {
255256
return analyze {
256257
this@declarations.let {

test-utils/testData/api/hello.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,18 @@ fun <D> foo(c: C, dd: () -> D) = 1
9696

9797
class CC: C() {}
9898

99+
public interface K1 {
100+
fun getProp(): String = "1"
101+
}
102+
103+
public interface K2 {
104+
val prop: String = "2"
105+
}
106+
107+
// FILE: JI.java
108+
public interface JI extends K1, K2 {
109+
}
110+
99111
// FILE: C.java
100112
import java.util.List;
101113
import java.util.ArrayList;

0 commit comments

Comments
 (0)