Skip to content

Commit 13007fa

Browse files
dimonchik0036Space Team
authored and
Space Team
committed
[LC] KtLightElementBase: textRange and textOffset should return only real values
It is up to clients to decide how to properly manage elements without ranges. With the previous implementation there was no way to detect such a situation. ^KT-70001 Fixed
1 parent 6405ad4 commit 13007fa

File tree

5 files changed

+16
-13
lines changed

5 files changed

+16
-13
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -24,9 +24,9 @@ abstract class KtLightElementBase(private var parent: PsiElement) : LightElement
2424
}
2525

2626
override fun getText() = kotlinOrigin?.text ?: ""
27-
override fun getTextRange() = kotlinOrigin?.textRange ?: TextRange.EMPTY_RANGE
28-
override fun getTextOffset() = kotlinOrigin?.textOffset ?: 0
29-
override fun getStartOffsetInParent() = kotlinOrigin?.startOffsetInParent ?: 0
27+
override fun getTextRange(): TextRange? = kotlinOrigin?.textRange
28+
override fun getTextOffset(): Int = kotlinOrigin?.textOffset ?: -1
29+
override fun getStartOffsetInParent(): Int = kotlinOrigin?.startOffsetInParent ?: -1
3030
override fun isWritable() = kotlinOrigin?.isWritable ?: false
3131
override fun getNavigationElement() = kotlinOrigin?.navigationElement ?: this
3232
override fun getUseScope() = kotlinOrigin?.useScope ?: super.getUseScope()

analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/methods/SymbolLightAccessorMethod.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ internal class SymbolLightAccessorMethod private constructor(
371371
return lightMemberOrigin?.auxiliaryOriginalElement?.textOffset ?: super.getTextOffset()
372372
}
373373

374-
override fun getTextRange(): TextRange {
374+
override fun getTextRange(): TextRange? {
375375
return lightMemberOrigin?.auxiliaryOriginalElement?.textRange ?: super.getTextRange()
376376
}
377377

analysis/symbol-light-classes/src/org/jetbrains/kotlin/light/classes/symbol/modifierLists/SymbolLightMemberModifierList.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -54,7 +54,7 @@ internal class SymbolLightMemberModifierList<T : KtLightMember<*>>(
5454
?: super.getTextOffset()
5555
}
5656

57-
override fun getTextRange(): TextRange {
57+
override fun getTextRange(): TextRange? {
5858
return getTextVariantFromModifierListOfPropertyAccessorIfNeeded(KtModifierList::getTextRange)
5959
?: super.getTextRange()
6060
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2022 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -75,7 +75,7 @@ private class KtUltraLightMethodModifierList(
7575
?: super.getTextOffset()
7676
}
7777

78-
override fun getTextRange(): TextRange {
78+
override fun getTextRange(): TextRange? {
7979
return getTextVariantFromModifierListOfPropertyAccessorIfNeeded(KtModifierList::getTextRange)
8080
?: super.getTextRange()
8181
}

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors.
2+
* Copyright 2010-2025 JetBrains s.r.o. and Kotlin Programming Language contributors.
33
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
44
*/
55

@@ -10,15 +10,18 @@ import com.intellij.psi.*
1010
import com.intellij.psi.scope.PsiScopeProcessor
1111
import com.intellij.psi.util.MethodSignature
1212
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod
13-
import org.jetbrains.kotlin.asJava.*
1413
import org.jetbrains.kotlin.asJava.builder.LightMemberOriginForDeclaration
1514
import org.jetbrains.kotlin.asJava.checkIsMangled
1615
import org.jetbrains.kotlin.asJava.classes.KtLightClass
1716
import org.jetbrains.kotlin.asJava.classes.cannotModify
1817
import org.jetbrains.kotlin.asJava.classes.lazyPub
18+
import org.jetbrains.kotlin.asJava.demangleInternalName
19+
import org.jetbrains.kotlin.asJava.propertyNameByAccessor
1920
import org.jetbrains.kotlin.asJava.unwrapped
2021
import org.jetbrains.kotlin.fileClasses.JvmFileClassUtil
21-
import org.jetbrains.kotlin.psi.*
22+
import org.jetbrains.kotlin.psi.KtAnnotationEntry
23+
import org.jetbrains.kotlin.psi.KtPropertyAccessor
24+
import org.jetbrains.kotlin.psi.KtPsiFactory
2225

2326
abstract class KtLightMethodImpl protected constructor(
2427
lightMemberOrigin: LightMemberOriginForDeclaration?,
@@ -141,7 +144,7 @@ abstract class KtLightMethodImpl protected constructor(
141144
?: super.getTextOffset()
142145
}
143146

144-
override fun getTextRange(): TextRange {
147+
override fun getTextRange(): TextRange? {
145148
return getTextVariantFromPropertyAccessorIfNeeded(KtPropertyAccessor::getTextRange)
146149
?: super.getTextRange()
147150
}

0 commit comments

Comments
 (0)