Add "Remove annotation" quickfix for @Throws override mismatch

This commit is contained in:
Svyatoslav Scherbina
2020-05-25 18:26:33 +03:00
parent 6461c1b4f1
commit 46caf27e70
5 changed files with 39 additions and 0 deletions
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtProperty
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm.*
import org.jetbrains.kotlin.resolve.konan.diagnostics.ErrorsNative.INCOMPATIBLE_THROWS_OVERRIDE
import org.jetbrains.kotlin.resolve.konan.diagnostics.ErrorsNative.MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND
import org.jetbrains.kotlin.resolve.konan.diagnostics.ErrorsNative.THROWS_LIST_EMPTY
@@ -656,5 +657,6 @@ class QuickFixRegistrar : QuickFixContributor {
MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND.registerFactory(AddExceptionToThrowsFix)
THROWS_LIST_EMPTY.registerFactory(RemoveAnnotationFix)
INCOMPATIBLE_THROWS_OVERRIDE.registerFactory(RemoveAnnotationFix)
}
}
@@ -0,0 +1,7 @@
package kotlin
import kotlin.reflect.KClass
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.CONSTRUCTOR)
@Retention(AnnotationRetention.SOURCE)
public annotation class Throws(vararg val exceptionClasses: KClass<out Throwable>)
@@ -0,0 +1,13 @@
// "Remove annotation" "true"
class MyException : Throwable()
interface Base {
@Throws(Throwable::class)
fun foo()
}
class Derived : Base {
<caret>@Throws(MyException::class)
override fun foo() {}
}
@@ -0,0 +1,12 @@
// "Remove annotation" "true"
class MyException : Throwable()
interface Base {
@Throws(Throwable::class)
fun foo()
}
class Derived : Base {
override fun foo() {}
}
@@ -830,6 +830,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
public void testRemoveEmptyThrows() throws Exception {
runTest("idea/testData/multiModuleQuickFix/fixNativeThrowsErrors/removeEmptyThrows/");
}
@TestMetadata("removeThrowsOnIncompatibleOverride")
public void testRemoveThrowsOnIncompatibleOverride() throws Exception {
runTest("idea/testData/multiModuleQuickFix/fixNativeThrowsErrors/removeThrowsOnIncompatibleOverride/");
}
}
@TestMetadata("idea/testData/multiModuleQuickFix/makeOverridenMemberOpen")