FIR checker: Enable ReplaceWithDotCallFix for UNNECESSARY_SAFE_CALL.
This commit is contained in:
committed by
Ilya Kirillov
parent
f1eeb72c01
commit
957f6ddafd
@@ -1136,6 +1136,7 @@ fun main(args: Array<String>) {
|
|||||||
model("quickfix/lateinit", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/lateinit", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
model("quickfix/modifiers", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
|
model("quickfix/modifiers", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
|
||||||
model("quickfix/override/typeMismatchOnOverride", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
|
model("quickfix/override/typeMismatchOnOverride", pattern = pattern, filenameStartsLowerCase = true, recursive = false)
|
||||||
|
model("quickfix/replaceWithDotCall", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
model("quickfix/replaceWithSafeCall", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/replaceWithSafeCall", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
model("quickfix/variables/changeMutability", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/variables/changeMutability", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
model("quickfix/addInitializer", pattern = pattern, filenameStartsLowerCase = true)
|
model("quickfix/addInitializer", pattern = pattern, filenameStartsLowerCase = true)
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ class MainKtQuickFixRegistrar : KtQuickFixRegistrar() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private val expressions = KtQuickFixesListBuilder.registerPsiQuickFix {
|
private val expressions = KtQuickFixesListBuilder.registerPsiQuickFix {
|
||||||
|
registerPsiQuickFixes(KtFirDiagnostic.UnnecessarySafeCall::class, ReplaceWithDotCallFix)
|
||||||
registerApplicator(ReplaceCallFixFactories.unsafeCallFactory)
|
registerApplicator(ReplaceCallFixFactories.unsafeCallFactory)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Generated
+38
@@ -344,6 +344,11 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall1.kt");
|
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall1.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unnecessarySafeCall2.kt")
|
||||||
|
public void testUnnecessarySafeCall2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeCall1.kt")
|
@TestMetadata("unsafeCall1.kt")
|
||||||
public void testUnsafeCall1() throws Exception {
|
public void testUnsafeCall1() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/unsafeCall1.kt");
|
runTest("idea/testData/quickfix/expressions/unsafeCall1.kt");
|
||||||
@@ -874,6 +879,39 @@ public class HighLevelQuickFixTestGenerated extends AbstractHighLevelQuickFixTes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/quickfix/replaceWithDotCall")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class ReplaceWithDotCall extends AbstractHighLevelQuickFixTest {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInReplaceWithDotCall() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/quickfix/replaceWithDotCall"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("comment.kt")
|
||||||
|
public void testComment() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/replaceWithDotCall/comment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("functionCall.kt")
|
||||||
|
public void testFunctionCall() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/replaceWithDotCall/functionCall.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("lineBreak.kt")
|
||||||
|
public void testLineBreak() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/replaceWithDotCall/lineBreak.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("normal.kt")
|
||||||
|
public void testNormal() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/replaceWithDotCall/normal.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/quickfix/replaceWithSafeCall")
|
@TestMetadata("idea/testData/quickfix/replaceWithSafeCall")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
+4
-5
@@ -11,7 +11,6 @@ import com.intellij.openapi.project.Project
|
|||||||
import com.intellij.psi.PsiDocumentManager
|
import com.intellij.psi.PsiDocumentManager
|
||||||
import com.intellij.psi.PsiElement
|
import com.intellij.psi.PsiElement
|
||||||
import com.intellij.psi.util.PsiTreeUtil
|
import com.intellij.psi.util.PsiTreeUtil
|
||||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
|
||||||
import org.jetbrains.kotlin.idea.KotlinBundle
|
import org.jetbrains.kotlin.idea.KotlinBundle
|
||||||
import org.jetbrains.kotlin.lexer.KtTokens
|
import org.jetbrains.kotlin.lexer.KtTokens
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -92,10 +91,10 @@ class ReplaceWithSafeCallForScopeFunctionFix(
|
|||||||
class ReplaceWithDotCallFix(expression: KtSafeQualifiedExpression) : ReplaceCallFix(expression, "."), CleanupFix {
|
class ReplaceWithDotCallFix(expression: KtSafeQualifiedExpression) : ReplaceCallFix(expression, "."), CleanupFix {
|
||||||
override fun getText() = KotlinBundle.message("replace.with.dot.call")
|
override fun getText() = KotlinBundle.message("replace.with.dot.call")
|
||||||
|
|
||||||
companion object : KotlinSingleIntentionActionFactory() {
|
companion object : QuickFixesPsiBasedFactory<PsiElement>(PsiElement::class, PsiElementSuitabilityCheckers.ALWAYS_SUITABLE) {
|
||||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
override fun doCreateQuickFix(psiElement: PsiElement): List<IntentionAction> {
|
||||||
val qualifiedExpression = diagnostic.psiElement.getParentOfType<KtSafeQualifiedExpression>(strict = false) ?: return null
|
val qualifiedExpression = psiElement.getParentOfType<KtSafeQualifiedExpression>(strict = false) ?: return emptyList()
|
||||||
return ReplaceWithDotCallFix(qualifiedExpression)
|
return listOfNotNull(ReplaceWithDotCallFix(qualifiedExpression))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,5 +2,3 @@
|
|||||||
fun foo(a: Any) {
|
fun foo(a: Any) {
|
||||||
a<caret>?.equals(0)
|
a<caret>?.equals(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
@@ -2,5 +2,3 @@
|
|||||||
fun foo(a: Any) {
|
fun foo(a: Any) {
|
||||||
a<caret>.equals(0)
|
a<caret>.equals(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* IGNORE_FIR */
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// "Replace with dot call" "true"
|
||||||
|
fun Any.foo() {
|
||||||
|
this<caret>?.equals(0)
|
||||||
|
}
|
||||||
@@ -1,7 +1,4 @@
|
|||||||
// "Replace with dot call" "true"
|
// "Replace with dot call" "true"
|
||||||
fun foo(a: Any) {
|
fun Any.foo() {
|
||||||
when (a) {
|
this.equals(0)
|
||||||
.equals(0) => true
|
|
||||||
else => false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -7757,6 +7757,11 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
|||||||
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall1.kt");
|
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall1.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("unnecessarySafeCall2.kt")
|
||||||
|
public void testUnnecessarySafeCall2() throws Exception {
|
||||||
|
runTest("idea/testData/quickfix/expressions/unnecessarySafeCall2.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("unsafeCall1.kt")
|
@TestMetadata("unsafeCall1.kt")
|
||||||
public void testUnsafeCall1() throws Exception {
|
public void testUnsafeCall1() throws Exception {
|
||||||
runTest("idea/testData/quickfix/expressions/unsafeCall1.kt");
|
runTest("idea/testData/quickfix/expressions/unsafeCall1.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user