Skip to content

Commit 2068629

Browse files
committed
Refactored to not use too many local functions
1 parent 940ce27 commit 2068629

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,27 @@ class KotlinInlineValHandler : InlineActionHandler() {
115115
preProcessInternalUsages(initializer, referenceExpressions)
116116
}
117117

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)
120139
descriptor.returnType ?: TypeUtils.NO_EXPECTED_TYPE
121140
else
122141
TypeUtils.NO_EXPECTED_TYPE
@@ -128,35 +147,22 @@ class KotlinInlineValHandler : InlineActionHandler() {
128147
expectedType = expectedType)
129148
}
130149

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)
138154

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)
150156

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")
155162
}
156-
project.checkConflictsInteractively(conflicts) { performRefactoring() }
157163
}
158164
else {
159-
performRefactoring()
165+
dialog.doAction()
160166
}
161167
}
162168

0 commit comments

Comments
 (0)