KT-24515 Intention to add an exception under the cursor to @Throws annotations

This commit is contained in:
Toshiaki Kameyama
2018-11-05 20:25:00 +09:00
committed by Yan Zhulanow
parent 3918ec71be
commit a621171d9b
48 changed files with 623 additions and 0 deletions
@@ -0,0 +1 @@
org.jetbrains.kotlin.idea.intentions.AddThrowsAnnotationIntention
@@ -0,0 +1,5 @@
fun test() {
<caret>throw java.io.IOException()
}
// RUNTIME_WITH_FULL_JDK
@@ -0,0 +1,8 @@
import java.io.IOException
@Throws(IOException::class)
fun test() {
throw java.io.IOException()
}
// RUNTIME_WITH_FULL_JDK
@@ -0,0 +1,8 @@
class FooException : Exception()
@Throws(FooException::class)
fun test() {
<caret>throw java.io.IOException()
}
// RUNTIME_WITH_FULL_JDK
@@ -0,0 +1,10 @@
import java.io.IOException
class FooException : Exception()
@Throws(FooException::class, IOException::class)
fun test() {
throw java.io.IOException()
}
// RUNTIME_WITH_FULL_JDK
@@ -0,0 +1,8 @@
// WITH_RUNTIME
class Test {
fun a() {
<caret>throw myError()
}
}
fun myError() = RuntimeException()
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class Test {
@Throws(RuntimeException::class)
fun a() {
throw myError()
}
}
fun myError() = RuntimeException()
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(BarException::class)
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(BarException::class, FooException::class)
fun test() {
throw FooException()
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// DISABLE-ERRORS
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = BarException::class)
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// DISABLE-ERRORS
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = [BarException::class, FooException::class])
fun test() {
throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = [BarException::class])
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = [BarException::class, FooException::class])
fun test() {
throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = arrayOf(BarException::class))
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = arrayOf(BarException::class, FooException::class))
fun test() {
throw FooException()
}
@@ -0,0 +1,12 @@
// DISABLE-ERRORS
// WITH_RUNTIME
// IS_APPLICABLE: false
class FooException : Exception()
class BarException : Exception()
@Throws(exceptionClasses = listOf(BarException::class))
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class FooException : Exception()
@Throws()
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class FooException : Exception()
@Throws(FooException::class)
fun test() {
throw FooException()
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class FooException : Exception()
@Throws
fun test() {
throw FooException()<caret>
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
class FooException : Exception()
@Throws(FooException::class)
fun test() {
throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class FooException : Exception()
@Throws(FooException::class)
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
// DISABLE-ERRORS
// IS_APPLICABLE: false
class FooException : Exception()
@Throws(exceptionClasses = FooException::class)
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class FooException : Exception()
@Throws(exceptionClasses = [FooException::class])
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class FooException : Exception()
@Throws(exceptionClasses = arrayOf(FooException::class))
fun test() {
<caret>throw FooException()
}
+5
View File
@@ -0,0 +1,5 @@
// WITH_RUNTIME
fun a(b: Boolean) {
<caret>throw if (b) RuntimeException() else Exception()
}
@@ -0,0 +1,6 @@
// WITH_RUNTIME
@Throws(Throwable::class)
fun a(b: Boolean) {
throw if (b) RuntimeException() else Exception()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
constructor() {
<caret>throw FooException()
}
}
@@ -0,0 +1,10 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
@Throws(FooException::class)
constructor() {
throw FooException()
}
}
@@ -0,0 +1,8 @@
// INTENTION_TEXT: "Add '@Throws' annotation"
// WITH_RUNTIME
class FooException : Exception()
fun test() {
<caret>throw FooException()
}
@@ -0,0 +1,9 @@
// INTENTION_TEXT: "Add '@Throws' annotation"
// WITH_RUNTIME
class FooException : Exception()
@Throws(FooException::class)
fun test() {
throw FooException()
}
@@ -0,0 +1,8 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
val getter: String
get() = <caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
val getter: String
@Throws(FooException::class)
get() = throw FooException()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
@get:Throws(RuntimeException::class)
val a: String
get() = <caret>throw Exception()
@@ -0,0 +1,5 @@
// WITH_RUNTIME
@get:Throws(RuntimeException::class, Exception::class)
val a: String
get() = throw Exception()
@@ -0,0 +1,8 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
class X {
init {
<caret>throw RuntimeException()
}
}
@@ -0,0 +1,4 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
val f = { <caret>throw RuntimeException() }
@@ -0,0 +1,8 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
var setter: String = ""
set(value) = <caret>throw FooException()
}
@@ -0,0 +1,9 @@
// WITH_RUNTIME
class FooException : Exception()
class Test {
var setter: String = ""
@Throws(FooException::class)
set(value) = throw FooException()
}
@@ -0,0 +1,5 @@
// WITH_RUNTIME
@set:Throws(RuntimeException::class)
var setter: String = ""
set(value) = <caret>throw Exception()
@@ -0,0 +1,5 @@
// WITH_RUNTIME
@set:Throws(RuntimeException::class, Exception::class)
var setter: String = ""
set(value) = throw Exception()
+6
View File
@@ -0,0 +1,6 @@
// JS
// IS_APPLICABLE: false
fun a() {
<caret>throw RuntimeException()
}
@@ -0,0 +1,7 @@
// WITH_RUNTIME
// IS_APPLICABLE: false
fun a() {
class Ex : RuntimeException()
<caret>throw Ex()
}