[PSI] Don't calculate ClassIds for local classes in call elements

- The fix uses relevant logic from  `getNonLocalContainingDeclaration`.
- The annotation entry case is covered by `KtCallElement` because
  `KtAnnotationEntry` is a subtype of it.
- KT-66038 is fixed by this because the static declaration provider only
  indexes non-local classes.

^KT-66038 fixed
This commit is contained in:
Marco Pennekamp
2024-02-22 18:17:03 +01:00
committed by Space Team
parent d52860b835
commit ea2bb32bc0
3 changed files with 10 additions and 4 deletions
@@ -1,2 +1,2 @@
/* ClassId: /Bar */@Retention(if (true) { /* ClassId: /Bar.Foo */class Foo })
/* ClassId: /Bar */@Retention(if (true) { /* ClassId: null */class Foo })
class Bar
@@ -1,3 +1,3 @@
// KT-24323
@Retention(AnnotationRetention.RUNTIME
annotation /* ClassId: /Validation */class Validation()
annotation /* ClassId: null */class Validation()
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.psi.psiUtil
import com.intellij.psi.PsiErrorElement
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.SpecialNames
@@ -17,7 +18,12 @@ internal object ClassIdCalculator {
for (element in declaration.parentsWithSelf) {
when (element) {
is KtEnumEntry -> {
is KtEnumEntry,
is KtCallElement,
is KtObjectLiteralExpression,
is KtCodeFragment,
is PsiErrorElement,
-> {
return null
}
is KtClassLikeDeclaration -> {
@@ -30,7 +36,7 @@ internal object ClassIdCalculator {
is KtScript -> {
// Skip script parent
}
is KtDeclaration, is KtObjectLiteralExpression -> {
is KtDeclaration -> {
// Local declarations don't have a 'ClassId'
return null
}