Light classes: Fix getTextOffset() and getTextRange() for property accessors

Before this commit, getTextOffset() and getTextRange() coming from the super class, returned numbers for the property, not for its accessor. This commit fixes the inconsistency.
This commit is contained in:
Yan Zhulanow
2019-07-03 18:03:42 +09:00
parent 7078302e6c
commit 36e1149e51
6 changed files with 98 additions and 17 deletions
@@ -7,8 +7,10 @@ package org.jetbrains.kotlin.idea.lightClasses
import com.intellij.psi.PsiMethod
import com.intellij.testFramework.LightProjectDescriptor
import org.jetbrains.kotlin.asJava.classes.KtLightClass
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
import org.junit.runner.RunWith
@@ -33,6 +35,35 @@ class LightClassBehaviorTest : KotlinLightCodeInsightFixtureTestCase() {
assert(offset == range.startOffset)
}
fun testPropertyAccessorOffsets() {
myFixture.configureByText(
"test.kt", """
class A {
var a: Int
get() = 5
set(v) {}
}
""".trimIndent()
)
val aClass = myFixture.javaFacade.findClass("A") as KtLightClass
val getAMethod = aClass.findMethodsByName("getA").single() as PsiMethod
val setAMethod = aClass.findMethodsByName("setA").single() as PsiMethod
val ktClass = aClass.kotlinOrigin!!
val ktProperty = ktClass.declarations.filterIsInstance<KtProperty>().single()
assert(getAMethod.textOffset != setAMethod.textOffset)
assert(getAMethod.textOffset > 0)
assert(getAMethod.textOffset != ktProperty.textOffset)
assert(getAMethod.textOffset == getAMethod.textRange.startOffset)
assert(setAMethod.textOffset > 0)
assert(setAMethod.textOffset != ktProperty.textOffset)
assert(setAMethod.textOffset == setAMethod.textRange.startOffset)
}
override fun getProjectDescriptor(): LightProjectDescriptor {
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
}