Extract Function/Parameter/Type Alias: Automatically quote declaration name when necessary
#KT-13157 Fixed
This commit is contained in:
@@ -243,6 +243,7 @@ Using 'this' as function argument in constructor of non-final class
|
||||
- [`KT-12945`](https://youtrack.jetbrains.com/issue/KT-12945) Rename: Fix function description in super method warning dialog
|
||||
- [`KT-12922`](https://youtrack.jetbrains.com/issue/KT-12922) Introduce Variable: Do not suggest expressions without type
|
||||
- [`KT-12943`](https://youtrack.jetbrains.com/issue/KT-12943) Rename: Show function signatures in "Rename Overloads" dialog
|
||||
- [`KT-13157`](https://youtrack.jetbrains.com/issue/KT-13157) Extract Function: Automatically quote function name if necessary
|
||||
|
||||
##### New features
|
||||
|
||||
|
||||
+2
-1
@@ -31,6 +31,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||
import org.jetbrains.kotlin.idea.core.UtilsKt;
|
||||
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtilKt;
|
||||
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle;
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.*;
|
||||
@@ -91,7 +92,7 @@ public class KotlinExtractFunctionDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
private String getFunctionName() {
|
||||
return functionNameField.getEnteredName();
|
||||
return UtilsKt.quoteIfNeeded(functionNameField.getEnteredName());
|
||||
}
|
||||
|
||||
private String getVisibility() {
|
||||
|
||||
+1
-1
@@ -270,7 +270,7 @@ private fun makeCall(
|
||||
}
|
||||
}
|
||||
|
||||
val calleeName = declaration.name
|
||||
val calleeName = declaration.name?.quoteIfNeeded()
|
||||
val callText = when (declaration) {
|
||||
is KtNamedFunction -> {
|
||||
val argumentsText = arguments.joinToString(separator = ", ", prefix = "(", postfix = ")")
|
||||
|
||||
+3
-2
@@ -27,6 +27,7 @@ import com.intellij.ui.NonFocusableCheckBox
|
||||
import com.intellij.usageView.BaseUsageViewDescriptor
|
||||
import com.intellij.usageView.UsageInfo
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType
|
||||
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.idea.refactoring.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.refactoring.runRefactoringWithPostprocessing
|
||||
import org.jetbrains.kotlin.idea.refactoring.validateElement
|
||||
@@ -230,7 +231,7 @@ class KotlinIntroduceParameterDialog private constructor(
|
||||
|
||||
override fun canRun() {
|
||||
val psiFactory = KtPsiFactory(myProject)
|
||||
psiFactory.createSimpleName(nameField.enteredName).validateElement("Invalid parameter name")
|
||||
psiFactory.createSimpleName(nameField.enteredName.quoteIfNeeded()).validateElement("Invalid parameter name")
|
||||
psiFactory.createType(typeField.enteredName).validateElement("Invalid parameter type")
|
||||
}
|
||||
|
||||
@@ -256,7 +257,7 @@ class KotlinIntroduceParameterDialog private constructor(
|
||||
return KtPsiFactory(myProject).createExpression(text)
|
||||
}
|
||||
|
||||
val chosenName = nameField.enteredName
|
||||
val chosenName = nameField.enteredName.quoteIfNeeded()
|
||||
var chosenType = typeField.enteredName
|
||||
var newArgumentValue = descriptor.newArgumentValue
|
||||
var newReplacer = descriptor.occurrenceReplacer
|
||||
|
||||
+2
-5
@@ -37,10 +37,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.getResolutionFacade
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.codeInsight.CodeInsightUtils
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.NewDeclarationNameValidator
|
||||
import org.jetbrains.kotlin.idea.core.moveInsideParenthesesAndReplaceWith
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.core.*
|
||||
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringBundle
|
||||
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.*
|
||||
@@ -319,7 +316,7 @@ open class KotlinIntroduceParameterHandler(
|
||||
originalRange = originalExpression.toRange(),
|
||||
callable = targetParent,
|
||||
callableDescriptor = functionDescriptor,
|
||||
newParameterName = suggestedNames.first(),
|
||||
newParameterName = suggestedNames.first().quoteIfNeeded(),
|
||||
newParameterTypeText = IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(replacementType),
|
||||
argumentValue = originalExpression,
|
||||
withDefaultValue = false,
|
||||
|
||||
+2
-1
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
|
||||
import org.jetbrains.kotlin.idea.core.compareDescriptors
|
||||
import org.jetbrains.kotlin.idea.core.quoteIfNeeded
|
||||
import org.jetbrains.kotlin.idea.util.getResolutionScope
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.KotlinPsiRange
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.KotlinPsiUnifier
|
||||
@@ -149,7 +150,7 @@ fun IntroduceTypeAliasDescriptor.validate(): IntroduceTypeAliasDescriptorWithCon
|
||||
}
|
||||
|
||||
fun findDuplicates(typeAlias: KtTypeAlias): Map<KotlinPsiRange, () -> Unit> {
|
||||
val aliasName = typeAlias.name ?: return emptyMap()
|
||||
val aliasName = typeAlias.name?.quoteIfNeeded() ?: return emptyMap()
|
||||
val typeAliasDescriptor = typeAlias.resolveToDescriptor() as TypeAliasDescriptor
|
||||
|
||||
val unifierParameters = typeAliasDescriptor.declaredTypeParameters.map { UnifierParameter(it, null) }
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.idea.KotlinFileType;
|
||||
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester;
|
||||
import org.jetbrains.kotlin.idea.core.UtilsKt;
|
||||
import org.jetbrains.kotlin.idea.refactoring.KotlinRefactoringUtilKt;
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceTypeAlias.IntroduceTypeAliasDescriptor;
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.introduceTypeAlias.IntroduceTypeAliasImplKt;
|
||||
@@ -93,7 +94,7 @@ public class KotlinIntroduceTypeAliasDialog extends DialogWrapper {
|
||||
}
|
||||
|
||||
private String getAliasName() {
|
||||
return aliasNameField.getEnteredName();
|
||||
return UtilsKt.quoteIfNeeded(aliasNameField.getEnteredName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
Reference in New Issue
Block a user