Skip to content

Commit 00c5df5

Browse files
committed
[ULC] Fix annotations invalid parents
Fixed #KT-45287
1 parent 1dd17cf commit 00c5df5

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightElementBase.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ import com.intellij.psi.impl.light.LightElement
2323
import org.jetbrains.kotlin.idea.KotlinLanguage
2424
import org.jetbrains.kotlin.psi.KtElement
2525

26-
abstract class KtLightElementBase(private val parent: PsiElement) : LightElement(parent.manager, KotlinLanguage.INSTANCE) {
26+
abstract class KtLightElementBase(private var parent: PsiElement) : LightElement(parent.manager, KotlinLanguage.INSTANCE) {
2727
override fun toString() = "${this.javaClass.simpleName} of $parent"
2828
override fun getParent(): PsiElement = parent
2929

3030
abstract val kotlinOrigin: KtElement?
3131

32+
internal fun setParent(newParent: PsiElement) {
33+
parent = newParent
34+
}
35+
3236
override fun getText() = kotlinOrigin?.text ?: ""
3337
override fun getTextRange() = kotlinOrigin?.textRange ?: TextRange.EMPTY_RANGE
3438
override fun getTextOffset() = kotlinOrigin?.textOffset ?: 0

compiler/light-classes/src/org/jetbrains/kotlin/asJava/elements/KtLightModifierList.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ abstract class KtLightModifierList<out T : KtLightElement<KtModifierListOwner, P
6161

6262
private fun computeAnnotations(): List<KtLightAbstractAnnotation> {
6363
val annotationsForEntries = owner.givenAnnotations ?: lightAnnotationsForEntries(this)
64+
//TODO: Hacky way to update wrong parents for annotations
65+
annotationsForEntries.forEach {
66+
it.parent = this
67+
}
6468
val modifierListOwner = parent
6569
if (modifierListOwner is KtLightClassForSourceDeclaration && modifierListOwner.isAnnotationType) {
6670

compiler/testData/asJava/ultraLightClasses/annotations.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,5 @@ class Foo @Anno constructor(dependency: MyDependency) {
6161
class Example(@field:Ann val foo: String, // annotate Java field
6262
@get:Ann val bar: String, // annotate Java getter
6363
@param:Ann val quux: String) // annotate Java constructor parameter
64+
65+
class CtorAnnotations(@Anno val x: String, @param:Anno val y: String, val z: String)

0 commit comments

Comments
 (0)