Light classes: Fix getTextOffset() for identifiers
Before this commit, getTextOffset() and getTextRange() implementations were inconsistent.
This commit is contained in:
@@ -46,4 +46,5 @@ open class KtLightIdentifier(
|
|||||||
override fun getParent() = lightOwner
|
override fun getParent() = lightOwner
|
||||||
override fun getContainingFile() = lightOwner.containingFile
|
override fun getContainingFile() = lightOwner.containingFile
|
||||||
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
|
override fun getTextRange() = origin?.textRange ?: TextRange.EMPTY_RANGE
|
||||||
|
override fun getTextOffset(): Int = origin?.textOffset ?: -1
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.idea.lightClasses
|
||||||
|
|
||||||
|
import com.intellij.psi.PsiMethod
|
||||||
|
import com.intellij.testFramework.LightProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase
|
||||||
|
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
|
||||||
|
import org.jetbrains.kotlin.test.JUnit3WithIdeaConfigurationRunner
|
||||||
|
import org.junit.runner.RunWith
|
||||||
|
|
||||||
|
@RunWith(JUnit3WithIdeaConfigurationRunner::class)
|
||||||
|
class LightClassBehaviorTest : KotlinLightCodeInsightFixtureTestCase() {
|
||||||
|
fun testIdentifierOffsets() {
|
||||||
|
myFixture.configureByText(
|
||||||
|
"test.kt", """
|
||||||
|
class A {
|
||||||
|
fun foo() {}
|
||||||
|
}
|
||||||
|
""".trimIndent()
|
||||||
|
)
|
||||||
|
|
||||||
|
val aClass = myFixture.javaFacade.findClass("A")!!
|
||||||
|
val fooMethodName = (aClass.findMethodsByName("foo").single() as PsiMethod).nameIdentifier!!
|
||||||
|
|
||||||
|
val offset = fooMethodName.textOffset
|
||||||
|
val range = fooMethodName.textRange
|
||||||
|
|
||||||
|
assert(offset > 0)
|
||||||
|
assert(offset == range.startOffset)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getProjectDescriptor(): LightProjectDescriptor {
|
||||||
|
return KotlinWithJdkAndRuntimeLightProjectDescriptor.INSTANCE
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user