Do not suggest "Rename to _" quick-fix for parameter of named function
#KT-14586 Fixed
This commit is contained in:
@@ -34,7 +34,15 @@ class RenameToUnderscoreFix(element: KtCallableDeclaration) : KotlinQuickFixActi
|
|||||||
companion object Factory : KotlinSingleIntentionActionFactory() {
|
companion object Factory : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||||
val declaration: KtCallableDeclaration? = when (diagnostic.factory) {
|
val declaration: KtCallableDeclaration? = when (diagnostic.factory) {
|
||||||
Errors.UNUSED_PARAMETER -> diagnostic.psiElement as? KtParameter
|
Errors.UNUSED_PARAMETER -> {
|
||||||
|
val parameter = diagnostic.psiElement as? KtParameter
|
||||||
|
val owner = parameter?.parent?.parent
|
||||||
|
|
||||||
|
if (owner is KtFunctionLiteral || (owner is KtNamedFunction && owner.name == null))
|
||||||
|
parameter
|
||||||
|
else
|
||||||
|
null
|
||||||
|
}
|
||||||
Errors.UNUSED_VARIABLE, Errors.UNUSED_DESTRUCTURED_PARAMETER_ENTRY ->
|
Errors.UNUSED_VARIABLE, Errors.UNUSED_DESTRUCTURED_PARAMETER_ENTRY ->
|
||||||
diagnostic.psiElement as? KtDestructuringDeclarationEntry
|
diagnostic.psiElement as? KtDestructuringDeclarationEntry
|
||||||
else -> null
|
else -> null
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
// ACTION: Make 'Nested' internal
|
// ACTION: Make 'Nested' internal
|
||||||
// ACTION: Make 'Nested' public
|
// ACTION: Make 'Nested' public
|
||||||
// ACTION: Remove parameter 'arg'
|
// ACTION: Remove parameter 'arg'
|
||||||
// ACTION: Rename to _
|
|
||||||
// ACTION: Convert to expression body
|
// ACTION: Convert to expression body
|
||||||
// ERROR: 'internal' function exposes its 'private' parameter type argument Nested
|
// ERROR: 'internal' function exposes its 'private' parameter type argument Nested
|
||||||
// ERROR: Cannot access 'Nested': it is private in 'Outer'
|
// ERROR: Cannot access 'Nested': it is private in 'Outer'
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// "Rename to _" "false"
|
||||||
|
// ACTION: Convert parameter to receiver
|
||||||
|
// ACTION: Remove parameter 'x'
|
||||||
|
|
||||||
|
fun foo(x<caret>: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -7496,6 +7496,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noActionForCommonFunction.kt")
|
||||||
|
public void testNoActionForCommonFunction() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/renameToUnderscore/noActionForCommonFunction.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("noActionForCommonVal.kt")
|
@TestMetadata("noActionForCommonVal.kt")
|
||||||
public void testNoActionForCommonVal() throws Exception {
|
public void testNoActionForCommonVal() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/renameToUnderscore/noActionForCommonVal.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/renameToUnderscore/noActionForCommonVal.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user