correctly implement JetSimpleNameReference.getTextRange() so that it doesn't include the @ character for references in labels

#KT-7560 Fixed
This commit is contained in:
Dmitry Jemerov
2015-04-29 19:11:31 +02:00
committed by Alexey Sedunov
parent ca8fb53ccd
commit 093878bd06
4 changed files with 19 additions and 1 deletions
@@ -61,7 +61,11 @@ public class JetSimpleNameReference(
return super.isReferenceTo(element)
}
override fun getRangeInElement(): TextRange = TextRange(0, getElement().getTextLength())
override fun getRangeInElement(): TextRange {
val element = getElement().getReferencedNameElement()
val startOffset = getElement().getTextRange().getStartOffset()
return element.getTextRange().shiftRight(-startOffset)
}
override fun canRename(): Boolean {
if (expression.getParentOfTypeAndBranch<JetWhenConditionInRange>(strict = true){ getOperationReference() } != null) return false
@@ -0,0 +1,5 @@
fun xyzzy(): Any {
fun b<caret>ar(): Int {
return@bar 1
}
}
@@ -0,0 +1,5 @@
fun xyzzy(): Any {
fun foo(): Int {
return@foo 1
}
}
@@ -124,6 +124,10 @@ public class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
doTestInplaceRename(null)
}
public fun testLabelFromFunction() {
doTestInplaceRename("foo")
}
private fun doTestInplaceRename(newName: String?) {
configureByFile(getTestName(false) + ".kt")
val element = TargetElementUtilBase.findTargetElement(