Quick Fixes: Use simple class name in "Change function return type" quickfix
#KT-12919 Fixed
This commit is contained in:
@@ -202,6 +202,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
|
||||
- [`KT-13055`](https://youtrack.jetbrains.com/issue/KT-13055) Exception in "Specify Type Explicitly" intention
|
||||
- [`KT-12942`](https://youtrack.jetbrains.com/issue/KT-12942) "Replace 'when' with 'if'" intention changes semantics when 'if' statements are used
|
||||
- [`KT-12646`](https://youtrack.jetbrains.com/issue/KT-12646) 'Convert to block body' should use partial body resolve
|
||||
- [`KT-12919`](https://youtrack.jetbrains.com/issue/KT-12919) Use simple class name in "Change function return type" quickfix
|
||||
- [`KT-13151`](https://youtrack.jetbrains.com/issue/KT-13151) Incorrect warning "Make variable immutable"
|
||||
- [`KT-13170`](https://youtrack.jetbrains.com/issue/KT-13170) "Declaration has platform type" inspection: by default should not be reported for platform type arguments
|
||||
- [`KT-13262`](https://youtrack.jetbrains.com/issue/KT-13262) "Wrap with safe let call" quickfix produces wrong result for qualified function
|
||||
|
||||
@@ -21,16 +21,17 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH
|
||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
|
||||
import org.jetbrains.kotlin.idea.project.builtIns
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getElementTextWithContext
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
@@ -68,7 +69,13 @@ class ChangeFunctionReturnTypeFix(element: KtFunction, type: KotlinType) : Kotli
|
||||
return changeFunctionLiteralReturnTypeFix.text
|
||||
}
|
||||
|
||||
val functionName = element.fqName?.asString() ?: element.name
|
||||
val shortName = element.name
|
||||
val functionName = if (shortName != null) {
|
||||
val containingDescriptor = element.resolveToDescriptor().containingDeclaration as? ClassDescriptor
|
||||
val containerName = containingDescriptor?.name
|
||||
if (containerName != null && !containerName.isSpecial) "${containerName.asString()}.$shortName" else shortName
|
||||
}
|
||||
else null
|
||||
|
||||
if (isUnitType && element.hasBlockBody()) {
|
||||
return if (functionName == null)
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Change 'foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
fun test() {
|
||||
val o = object {
|
||||
fun foo(): String {
|
||||
return <caret>1
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Change 'foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
fun test() {
|
||||
val o = object {
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Change 'Companion.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): String {
|
||||
return <caret>1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Change 'Companion.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
companion object {
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// "Change 'A.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
fun test() {
|
||||
class A {
|
||||
fun foo(): String {
|
||||
return <caret>1
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Change 'A.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
fun test() {
|
||||
class A {
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Change 'B.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
class B {
|
||||
fun foo(): String {
|
||||
return <caret>1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// "Change 'B.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
class B {
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Change 'A.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
fun foo(): String {
|
||||
return <caret>1
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Change 'A.foo' function return type to 'Int'" "true"
|
||||
package foo.bar
|
||||
|
||||
class A {
|
||||
fun foo(): Int {
|
||||
return 1
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8137,6 +8137,36 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeNoFqNameForAnonymousObject.kt")
|
||||
public void testChangeReturnTypeNoFqNameForAnonymousObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeNoFqNameForAnonymousObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeNoFqNameForCompanionObject.kt")
|
||||
public void testChangeReturnTypeNoFqNameForCompanionObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeNoFqNameForCompanionObject.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeNoFqNameForLocalClass.kt")
|
||||
public void testChangeReturnTypeNoFqNameForLocalClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeNoFqNameForLocalClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeNoFqNameForNestedClass.kt")
|
||||
public void testChangeReturnTypeNoFqNameForNestedClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeNoFqNameForNestedClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeNoFqNameForTopLevelClass.kt")
|
||||
public void testChangeReturnTypeNoFqNameForTopLevelClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeNoFqNameForTopLevelClass.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("changeReturnTypeToSpecificNullable.kt")
|
||||
public void testChangeReturnTypeToSpecificNullable() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/typeMismatch/changeReturnTypeToSpecificNullable.kt");
|
||||
|
||||
Reference in New Issue
Block a user