Wrong caption "Change to property access" for Quick Fix to convert class instantiation to object reference #KT-13870 Fixed (#1189)
This commit is contained in:
committed by
Dmitry Jemerov
parent
987c7f5be8
commit
865f9d4c7e
@@ -19,12 +19,17 @@ package org.jetbrains.kotlin.idea.quickfix
|
|||||||
import com.intellij.openapi.editor.Editor
|
import com.intellij.openapi.editor.Editor
|
||||||
import com.intellij.openapi.project.Project
|
import com.intellij.openapi.project.Project
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||||
|
import org.jetbrains.kotlin.idea.intentions.getCallableDescriptor
|
||||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject
|
||||||
|
|
||||||
class ChangeToPropertyAccessFix(element: KtCallExpression) : KotlinQuickFixAction<KtCallExpression>(element) {
|
class ChangeToPropertyAccessFix(
|
||||||
override fun getFamilyName() = "Change to property access"
|
element: KtCallExpression,
|
||||||
|
private val isObjectCall: Boolean) : KotlinQuickFixAction<KtCallExpression>(element) {
|
||||||
|
|
||||||
|
override fun getFamilyName() = if (isObjectCall) "Remove invocation" else "Change to property access"
|
||||||
|
|
||||||
override fun getText() = familyName
|
override fun getText() = familyName
|
||||||
|
|
||||||
@@ -36,8 +41,9 @@ class ChangeToPropertyAccessFix(element: KtCallExpression) : KotlinQuickFixActio
|
|||||||
companion object : KotlinSingleIntentionActionFactory() {
|
companion object : KotlinSingleIntentionActionFactory() {
|
||||||
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtCallExpression>? {
|
override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction<KtCallExpression>? {
|
||||||
val expression = diagnostic.psiElement.parent as? KtCallExpression ?: return null
|
val expression = diagnostic.psiElement.parent as? KtCallExpression ?: return null
|
||||||
if (expression is KtExpression && expression.valueArguments.isEmpty()) {
|
if (expression.valueArguments.isEmpty()) {
|
||||||
return ChangeToPropertyAccessFix(expression)
|
val isObjectCall = expression.calleeExpression?.getCallableDescriptor() is FakeCallableDescriptorForObject
|
||||||
|
return ChangeToPropertyAccessFix(expression, isObjectCall)
|
||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove invocation" "true"
|
||||||
|
enum class Test {
|
||||||
|
A
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
Test.A<caret>()
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
// "Remove invocation" "true"
|
||||||
|
enum class Test {
|
||||||
|
A
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
Test.A
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Remove invocation" "true"
|
||||||
|
object Test
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
Test<caret>()
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// "Remove invocation" "true"
|
||||||
|
object Test
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
Test
|
||||||
|
}
|
||||||
@@ -11422,12 +11422,24 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/variables/changeToPropertyAccess"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/variables/changeToPropertyAccess"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("enumEntryCall.kt")
|
||||||
|
public void testEnumEntryCall() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/enumEntryCall.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonSimpleName.kt")
|
@TestMetadata("nonSimpleName.kt")
|
||||||
public void testNonSimpleName() throws Exception {
|
public void testNonSimpleName() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/nonSimpleName.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/nonSimpleName.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectCall.kt")
|
||||||
|
public void testObjectCall() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/objectCall.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("propertyCall.kt")
|
@TestMetadata("propertyCall.kt")
|
||||||
public void testPropertyCall() throws Exception {
|
public void testPropertyCall() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/propertyCall.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/variables/changeToPropertyAccess/propertyCall.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user