From 20686297e5adf24514252a5b13f5a92af23c2007 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Mon, 22 May 2017 22:28:55 +0300 Subject: [PATCH] Refactored to not use too many local functions --- .../inline/KotlinInlineValHandler.kt | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt index 420ce8ed825..c49813883be 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/inline/KotlinInlineValHandler.kt @@ -115,8 +115,27 @@ class KotlinInlineValHandler : InlineActionHandler() { preProcessInternalUsages(initializer, referenceExpressions) } - val descriptor = element.resolveToDescriptor() as VariableDescriptor - val expectedType = if (element.typeReference != null) + if (foreignUsages.isNotEmpty()) { + val conflicts = MultiMap().apply { + putValue(null, "Property '$name' has non-Kotlin usages. They won't be processed by the Inline refactoring.") + foreignUsages.forEach { putValue(it, it.text) } + } + project.checkConflictsInteractively(conflicts) { performRefactoring(declaration, initializer, editor, assignment, isHighlighting) } + } + else { + performRefactoring(declaration, initializer, editor, assignment, isHighlighting) + } + } + + fun performRefactoring( + declaration: KtProperty, + initializer: KtExpression, + editor: Editor?, + assignment: KtBinaryExpression?, + isHighlighting: Boolean + ) { + val descriptor = declaration.resolveToDescriptor() as VariableDescriptor + val expectedType = if (declaration.typeReference != null) descriptor.returnType ?: TypeUtils.NO_EXPECTED_TYPE else TypeUtils.NO_EXPECTED_TYPE @@ -128,35 +147,22 @@ class KotlinInlineValHandler : InlineActionHandler() { expectedType = expectedType) } - fun performRefactoring() { - val reference = editor?.let { TargetElementUtil.findReference(it, it.caretModel.offset) } as? KtSimpleNameReference - val replacementBuilder = CodeToInlineBuilder(descriptor, element.getResolutionFacade()) - val replacement = replacementBuilder.prepareCodeToInline(initializerCopy, emptyList(), ::analyzeInitializerCopy) - val replacementStrategy = CallableUsageReplacementStrategy(replacement) + val reference = editor?.let { TargetElementUtil.findReference(it, it.caretModel.offset) } as? KtSimpleNameReference + val replacementBuilder = CodeToInlineBuilder(descriptor, declaration.getResolutionFacade()) + val replacement = replacementBuilder.prepareCodeToInline(initializerCopy, emptyList(), ::analyzeInitializerCopy) + val replacementStrategy = CallableUsageReplacementStrategy(replacement) - val dialog = KotlinInlineValDialog(declaration, reference, replacementStrategy, assignment) + val dialog = KotlinInlineValDialog(declaration, reference, replacementStrategy, assignment) - if (!ApplicationManager.getApplication().isUnitTestMode) { - dialog.show() - if (!dialog.isOK && isHighlighting) { - val statusBar = WindowManager.getInstance().getStatusBar(project) - statusBar?.info = RefactoringBundle.message("press.escape.to.remove.the.highlighting") - } + if (!ApplicationManager.getApplication().isUnitTestMode) { + dialog.show() + if (!dialog.isOK && isHighlighting) { + val statusBar = WindowManager.getInstance().getStatusBar(declaration.project) + statusBar?.info = RefactoringBundle.message("press.escape.to.remove.the.highlighting") } - else { - dialog.doAction() - } - } - - if (foreignUsages.isNotEmpty()) { - val conflicts = MultiMap().apply { - putValue(null, "Property '$name' has non-Kotlin usages. They won't be processed by the Inline refactoring.") - foreignUsages.forEach { putValue(it, it.text) } - } - project.checkConflictsInteractively(conflicts) { performRefactoring() } } else { - performRefactoring() + dialog.doAction() } }