mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] extract function: suggest numeric name in case of conflict
- also validate name, chosen from lookup ^KTIJ-30166 fixed GitOrigin-RevId: d346cd614784718cf8850ff7b074114154539575
This commit is contained in:
committed by
intellij-monorepo-bot
parent
852975f29c
commit
6c2c2db190
+8
-2
@@ -149,9 +149,15 @@ data class ExtractMethodTemplateBuilder(
|
||||
return editorOffsets.all { it in templateRange }
|
||||
}
|
||||
|
||||
private fun setTemplateValidator(templateState: TemplateState, validator: (TextRange) -> Boolean){
|
||||
private fun setTemplateValidator(templateState: TemplateState, validator: (TextRange) -> Boolean) {
|
||||
setupValidatorForAction(IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE, templateState, validator)
|
||||
setupValidatorForAction(IdeActions.ACTION_CHOOSE_LOOKUP_ITEM, templateState, validator)
|
||||
}
|
||||
|
||||
private fun setupValidatorForAction(actionName: String,
|
||||
templateState: TemplateState,
|
||||
validator: (TextRange) -> Boolean) {
|
||||
val manager = EditorActionManager.getInstance()
|
||||
val actionName = IdeActions.ACTION_EDITOR_NEXT_TEMPLATE_VARIABLE
|
||||
val defaultHandler = manager.getActionHandler(actionName)
|
||||
Disposer.register(templateState) { manager.setActionHandler(actionName, defaultHandler) }
|
||||
manager.setActionHandler(actionName, object : EditorActionHandler() {
|
||||
|
||||
+5
@@ -30,6 +30,11 @@ public class InplaceIntroduceFunctionTestGenerated extends AbstractInplaceIntrod
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("ConflictDefaultName.kt")
|
||||
public void testConflictDefaultName() throws Exception {
|
||||
runTest("testData/refactoring/extractFunctionInplace/ConflictDefaultName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConflictNameNotAccepted.kt")
|
||||
public void testConflictNameNotAccepted() throws Exception {
|
||||
runTest("testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt");
|
||||
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
fun sample(){
|
||||
<selection>println("42")</selection>
|
||||
}
|
||||
|
||||
fun extracted(){
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun sample(){
|
||||
extracted1<caret>()
|
||||
}
|
||||
|
||||
private fun extracted1() {
|
||||
println("42")
|
||||
}
|
||||
|
||||
fun extracted(){
|
||||
}
|
||||
+1
-1
@@ -186,6 +186,6 @@ abstract class AbstractExtractionDataAnalyzer<KotlinType, P : IMutableParameter<
|
||||
}
|
||||
}
|
||||
|
||||
return functionNames.toList().takeIf { it.isNotEmpty() } ?: listOf(Registry.stringValue("kotlin.extract.function.default.name"))
|
||||
return functionNames.toList().takeIf { it.isNotEmpty() } ?: listOf(KotlinNameSuggester.suggestNameByName(Registry.stringValue("kotlin.extract.function.default.name"), validator))
|
||||
}
|
||||
}
|
||||
+5
@@ -30,6 +30,11 @@ public class K2InplaceIntroduceFunctionTestGenerated extends AbstractK2InplaceIn
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("ConflictDefaultName.kt")
|
||||
public void testConflictDefaultName() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ConflictDefaultName.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ConflictNameNotAccepted.kt")
|
||||
public void testConflictNameNotAccepted() throws Exception {
|
||||
runTest("../../idea/tests/testData/refactoring/extractFunctionInplace/ConflictNameNotAccepted.kt");
|
||||
|
||||
Reference in New Issue
Block a user