Add "Remove annotation" quickfix for empty @Throws

This commit is contained in:
Svyatoslav Scherbina
2020-05-25 18:13:24 +03:00
parent b7a08494ae
commit 6461c1b4f1
7 changed files with 23 additions and 0 deletions
@@ -51,6 +51,7 @@ 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.MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND
import org.jetbrains.kotlin.resolve.konan.diagnostics.ErrorsNative.THROWS_LIST_EMPTY
class QuickFixRegistrar : QuickFixContributor {
override fun registerQuickFixes(quickFixes: QuickFixes) {
@@ -654,5 +655,6 @@ class QuickFixRegistrar : QuickFixContributor {
CONFLICTING_JVM_DECLARATIONS.registerFactory(AddJvmNameAnnotationFix)
MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND.registerFactory(AddExceptionToThrowsFix)
THROWS_LIST_EMPTY.registerFactory(RemoveAnnotationFix)
}
}
@@ -2,6 +2,7 @@
// ERROR: @Throws must have non-empty class list
// ACTION: Make internal
// ACTION: Make private
// ACTION: Remove annotation
// No compilation error => no quickfix.
<caret>@Throws()
@@ -2,6 +2,7 @@
// ERROR: @Throws must have non-empty class list
// ACTION: Make internal
// ACTION: Make private
// ACTION: Remove annotation
// No compilation error => no quickfix.
<caret>@Throws
@@ -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,4 @@
// "Remove annotation" "true"
<caret>@Throws
fun removeEmptyThrows() {}
@@ -0,0 +1,3 @@
// "Remove annotation" "true"
fun removeEmptyThrows() {}
@@ -825,6 +825,11 @@ public class QuickFixMultiModuleTestGenerated extends AbstractQuickFixMultiModul
public void testAllFilesPresentInFixNativeThrowsErrors() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("idea/testData/multiModuleQuickFix/fixNativeThrowsErrors"), Pattern.compile("^([^\\.]+)$"), null, true);
}
@TestMetadata("removeEmptyThrows")
public void testRemoveEmptyThrows() throws Exception {
runTest("idea/testData/multiModuleQuickFix/fixNativeThrowsErrors/removeEmptyThrows/");
}
}
@TestMetadata("idea/testData/multiModuleQuickFix/makeOverridenMemberOpen")