@@ -115,8 +115,27 @@ class KotlinInlineValHandler : InlineActionHandler() {
115
115
preProcessInternalUsages(initializer, referenceExpressions)
116
116
}
117
117
118
- val descriptor = element.resolveToDescriptor() as VariableDescriptor
119
- val expectedType = if (element.typeReference != null )
118
+ if (foreignUsages.isNotEmpty()) {
119
+ val conflicts = MultiMap <PsiElement , String >().apply {
120
+ putValue(null , " Property '$name ' has non-Kotlin usages. They won't be processed by the Inline refactoring." )
121
+ foreignUsages.forEach { putValue(it, it.text) }
122
+ }
123
+ project.checkConflictsInteractively(conflicts) { performRefactoring(declaration, initializer, editor, assignment, isHighlighting) }
124
+ }
125
+ else {
126
+ performRefactoring(declaration, initializer, editor, assignment, isHighlighting)
127
+ }
128
+ }
129
+
130
+ fun performRefactoring (
131
+ declaration : KtProperty ,
132
+ initializer : KtExpression ,
133
+ editor : Editor ? ,
134
+ assignment : KtBinaryExpression ? ,
135
+ isHighlighting : Boolean
136
+ ) {
137
+ val descriptor = declaration.resolveToDescriptor() as VariableDescriptor
138
+ val expectedType = if (declaration.typeReference != null )
120
139
descriptor.returnType ? : TypeUtils .NO_EXPECTED_TYPE
121
140
else
122
141
TypeUtils .NO_EXPECTED_TYPE
@@ -128,35 +147,22 @@ class KotlinInlineValHandler : InlineActionHandler() {
128
147
expectedType = expectedType)
129
148
}
130
149
131
- fun performRefactoring () {
132
- val reference = editor?.let { TargetElementUtil .findReference(it, it.caretModel.offset) } as ? KtSimpleNameReference
133
- val replacementBuilder = CodeToInlineBuilder (descriptor, element.getResolutionFacade())
134
- val replacement = replacementBuilder.prepareCodeToInline(initializerCopy, emptyList(), ::analyzeInitializerCopy)
135
- val replacementStrategy = CallableUsageReplacementStrategy (replacement)
136
-
137
- val dialog = KotlinInlineValDialog (declaration, reference, replacementStrategy, assignment)
150
+ val reference = editor?.let { TargetElementUtil .findReference(it, it.caretModel.offset) } as ? KtSimpleNameReference
151
+ val replacementBuilder = CodeToInlineBuilder (descriptor, declaration.getResolutionFacade())
152
+ val replacement = replacementBuilder.prepareCodeToInline(initializerCopy, emptyList(), ::analyzeInitializerCopy)
153
+ val replacementStrategy = CallableUsageReplacementStrategy (replacement)
138
154
139
- if (! ApplicationManager .getApplication().isUnitTestMode) {
140
- dialog.show()
141
- if (! dialog.isOK && isHighlighting) {
142
- val statusBar = WindowManager .getInstance().getStatusBar(project)
143
- statusBar?.info = RefactoringBundle .message(" press.escape.to.remove.the.highlighting" )
144
- }
145
- }
146
- else {
147
- dialog.doAction()
148
- }
149
- }
155
+ val dialog = KotlinInlineValDialog (declaration, reference, replacementStrategy, assignment)
150
156
151
- if (foreignUsages.isNotEmpty()) {
152
- val conflicts = MultiMap <PsiElement , String >().apply {
153
- putValue(null , " Property '$name ' has non-Kotlin usages. They won't be processed by the Inline refactoring." )
154
- foreignUsages.forEach { putValue(it, it.text) }
157
+ if (! ApplicationManager .getApplication().isUnitTestMode) {
158
+ dialog.show()
159
+ if (! dialog.isOK && isHighlighting) {
160
+ val statusBar = WindowManager .getInstance().getStatusBar(declaration.project)
161
+ statusBar?.info = RefactoringBundle .message(" press.escape.to.remove.the.highlighting" )
155
162
}
156
- project.checkConflictsInteractively(conflicts) { performRefactoring() }
157
163
}
158
164
else {
159
- performRefactoring ()
165
+ dialog.doAction ()
160
166
}
161
167
}
162
168
0 commit comments