Code cleanup includes deprecated symbol usage fixes + code cleanup does not crash on nested usages to fix
This commit is contained in:
@@ -16,8 +16,11 @@
|
||||
|
||||
package org.jetbrains.kotlin.idea.inspections
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import com.intellij.codeInspection.*
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.PsiJavaFile
|
||||
@@ -90,7 +93,8 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
|
||||
Errors.UNNECESSARY_SAFE_CALL,
|
||||
Errors.USELESS_CAST,
|
||||
Errors.USELESS_ELVIS,
|
||||
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION
|
||||
ErrorsJvm.POSITIONED_VALUE_ARGUMENT_FOR_JAVA_ANNOTATION,
|
||||
Errors.DEPRECATED_SYMBOL_WITH_MESSAGE
|
||||
)
|
||||
|
||||
private fun Diagnostic.isObsoleteLabel(): Boolean {
|
||||
@@ -98,10 +102,18 @@ public class KotlinCleanupInspection(): LocalInspectionTool(), CleanupLocalInspe
|
||||
return ReplaceObsoleteLabelSyntaxFix.looksLikeObsoleteLabel(annotationEntry)
|
||||
}
|
||||
|
||||
private class Wrapper(val intention: IntentionAction, file: JetFile) : IntentionWrapper(intention, file) {
|
||||
override fun invoke(project: Project, editor: Editor?, file: PsiFile?) {
|
||||
if (intention.isAvailable(project, editor, file)) { // we should check isAvailable here because some elements may get invalidated (or other conditions may change)
|
||||
super.invoke(project, editor, file)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun Diagnostic.toProblemDescriptor(file: JetFile, manager: InspectionManager): ProblemDescriptor? {
|
||||
val quickFixes = JetPsiChecker.createQuickfixes(this)
|
||||
.filter { it is CleanupFix }
|
||||
.map { IntentionWrapper(it, file) }
|
||||
.map { Wrapper(it, file) }
|
||||
|
||||
if (quickFixes.isEmpty()) return null
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
public class DeprecatedSymbolUsageFix(
|
||||
element: JetSimpleNameExpression/*TODO?*/,
|
||||
replaceWith: ReplaceWith
|
||||
) : DeprecatedSymbolUsageFixBase(element, replaceWith), HighPriorityAction {
|
||||
) : DeprecatedSymbolUsageFixBase(element, replaceWith), CleanupFix, HighPriorityAction {
|
||||
|
||||
override fun getFamilyName() = "Replace deprecated symbol usage"
|
||||
|
||||
|
||||
@@ -26,9 +26,12 @@ val x = fun foo(x: String) { }
|
||||
fun foo() {
|
||||
@loop
|
||||
for (i in 1..100) {
|
||||
val v = oldFun2(i as Int) as Int
|
||||
/* comment */
|
||||
continue@loop
|
||||
}
|
||||
|
||||
oldFun1(oldFun2(10))
|
||||
}
|
||||
|
||||
fun unnecessarySafeCall(x: String) {
|
||||
|
||||
@@ -28,9 +28,12 @@ val x = fun(x: String) { }
|
||||
fun foo() {
|
||||
loop@
|
||||
for (i in 1..100) {
|
||||
val v = oldFun2(i as Int)
|
||||
/* comment */
|
||||
continue@loop
|
||||
}
|
||||
|
||||
bar(bar(10 + 2) + 1)
|
||||
}
|
||||
|
||||
fun unnecessarySafeCall(x: String) {
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
@deprecated("", ReplaceWith("bar(p + 1)"))
|
||||
public fun oldFun1(p: Int): Int = 0
|
||||
|
||||
@deprecated("", ReplaceWith("bar(p + 2)"))
|
||||
public fun oldFun2(p: Int): Int = 0
|
||||
|
||||
public fun bar(p: Int): Int = p
|
||||
@@ -46,7 +46,7 @@ class KotlinCleanupInspectionTest(): JetLightCodeInsightFixtureTestCase() {
|
||||
}
|
||||
|
||||
public fun testCleanup() {
|
||||
doTest("cleanup.kt.after", "cleanup.kt", "JavaAnn.java")
|
||||
doTest("cleanup.kt.after", "cleanup.kt", "JavaAnn.java", "deprecatedSymbols.kt")
|
||||
}
|
||||
|
||||
public fun testDeprecatedFunctionClasses() {
|
||||
|
||||
Reference in New Issue
Block a user