@@ -28,6 +28,8 @@ import org.jetbrains.kotlin.idea.refactoring.rename.RenameKotlinImplicitLambdaPa
28
28
import com.intellij.codeInsight.template.impl.TemplateManagerImpl
29
29
import com.intellij.codeInsight.template.TemplateManager
30
30
import com.intellij.openapi.command.WriteCommandAction
31
+ import org.jetbrains.kotlin.idea.refactoring.rename.findElementForRename
32
+ import org.jetbrains.kotlin.psi.KtNameReferenceExpression
31
33
32
34
class InplaceRenameTest : LightPlatformCodeInsightTestCase () {
33
35
override fun isRunInWriteAction (): Boolean = false
@@ -50,19 +52,58 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
50
52
}
51
53
52
54
fun testFunctionLiteralIt () {
55
+ doTestImplicitLambdaParameter(" y" )
56
+ }
57
+
58
+ fun testFunctionLiteralItEndCaret () {
59
+ doTestImplicitLambdaParameter(" y" )
60
+ }
61
+
62
+ fun testFunctionLiteralParenthesis () {
63
+ doTestInplaceRename(" y" )
64
+ }
65
+
66
+ fun testLocalFunction () {
67
+ doTestInplaceRename(" bar" )
68
+ }
69
+
70
+ fun testFunctionParameterNotInplace () {
71
+ doTestInplaceRename(null )
72
+ }
73
+
74
+ fun testGlobalFunctionNotInplace () {
75
+ doTestInplaceRename(null )
76
+ }
77
+
78
+ fun testTopLevelValNotInplace () {
79
+ doTestInplaceRename(null )
80
+ }
81
+
82
+ fun testLabelFromFunction () {
83
+ doTestInplaceRename(" foo" )
84
+ }
85
+
86
+ fun testMultiDeclaration () {
87
+ doTestInplaceRename(" foo" )
88
+ }
89
+
90
+ fun testLocalVarShadowingMemberProperty () {
91
+ doTestInplaceRename(" name1" )
92
+ }
93
+
94
+ private fun doTestImplicitLambdaParameter (newName : String ) {
53
95
configureByFile(getTestName(false ) + " .kt" )
54
- val newName = " y"
55
96
56
97
// This code is copy-pasted from CodeInsightTestUtil.doInlineRename() and slightly modified.
57
98
// Original method was not suitable because it expects renamed element to be reference to other or referrable
58
99
59
- val file = LightPlatformCodeInsightTestCase . getFile()!!
60
- val editor = LightPlatformCodeInsightTestCase . getEditor()!!
61
- val element = file.findReferenceAt (editor.caretModel.offset)!! .element
100
+ val file = getFile()!!
101
+ val editor = getEditor()!!
102
+ val element = file.findElementForRename< KtNameReferenceExpression > (editor.caretModel.offset)!!
62
103
assertNotNull(element)
63
104
64
105
val dataContext = SimpleDataContext .getSimpleContext(CommonDataKeys .PSI_ELEMENT .name, element!! ,
65
- LightPlatformCodeInsightTestCase . getCurrentEditorDataContext())
106
+ getCurrentEditorDataContext())
66
107
val handler = RenameKotlinImplicitLambdaParameter ()
67
108
68
109
assertTrue(handler.isRenaming(dataContext), " In-place rename not allowed for " + element)
@@ -100,38 +141,6 @@ class InplaceRenameTest : LightPlatformCodeInsightTestCase() {
100
141
checkResultByFile(getTestName(false ) + " .kt.after" )
101
142
}
102
143
103
- fun testFunctionLiteralParenthesis () {
104
- doTestInplaceRename(" y" )
105
- }
106
-
107
- fun testLocalFunction () {
108
- doTestInplaceRename(" bar" )
109
- }
110
-
111
- fun testFunctionParameterNotInplace () {
112
- doTestInplaceRename(null )
113
- }
114
-
115
- fun testGlobalFunctionNotInplace () {
116
- doTestInplaceRename(null )
117
- }
118
-
119
- fun testTopLevelValNotInplace () {
120
- doTestInplaceRename(null )
121
- }
122
-
123
- fun testLabelFromFunction () {
124
- doTestInplaceRename(" foo" )
125
- }
126
-
127
- fun testMultiDeclaration () {
128
- doTestInplaceRename(" foo" )
129
- }
130
-
131
- fun testLocalVarShadowingMemberProperty () {
132
- doTestInplaceRename(" name1" )
133
- }
134
-
135
144
private fun doTestInplaceRename (newName : String? ) {
136
145
configureByFile(getTestName(false ) + " .kt" )
137
146
val element = TargetElementUtilBase .findTargetElement(
0 commit comments