-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
KDOC_WITHOUT_THROWS_TAG
add @throws
annotation when throw inside …
…try-catch (#1862) ### What's done: - Fixed `KDOC_WITHOUT_THROWS_TAG` rule when it adds a @throws annotation to the function, which has `throw` inside try-catch block - Added tests, using real exceptions Closes #1718
- Loading branch information
1 parent
02c1a7c
commit d14f27d
Showing
5 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
...ckage/src/main/kotlin/com/saveourtool/diktat/kdoc/methods/KdocWithoutThrowsTagExpected.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package test.paragraph2.kdoc.`package`.src.main.kotlin.com.saveourtool.diktat.kdoc.methods | ||
|
||
/** | ||
* @param onSuccess | ||
* @param onFailure | ||
* @throws ArrayIndexOutOfBounds | ||
*/ | ||
fun parseInputNumber(onSuccess: (number: Int) -> Unit, onFailure: () -> Unit) { | ||
try { | ||
val input: Int = binding.inputEditText.text.toString().toInt() | ||
if (input < 0) | ||
throw NumberFormatException() | ||
throw ArrayIndexOutOfBounds() | ||
throw NullPointerException() | ||
|
||
onSuccess(input) | ||
} catch (e: IllegalArgumentException) { | ||
onFailure() | ||
} catch (e: NullPointerException) { | ||
onFailure() | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...package/src/main/kotlin/com/saveourtool/diktat/kdoc/methods/KdocWithoutThrowsTagTested.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package test.paragraph2.kdoc.`package`.src.main.kotlin.com.saveourtool.diktat.kdoc.methods | ||
|
||
/** | ||
* @param onSuccess | ||
* @param onFailure | ||
*/ | ||
fun parseInputNumber(onSuccess: (number: Int) -> Unit, onFailure: () -> Unit) { | ||
try { | ||
val input: Int = binding.inputEditText.text.toString().toInt() | ||
if (input < 0) | ||
throw NumberFormatException() | ||
throw ArrayIndexOutOfBounds() | ||
throw NullPointerException() | ||
|
||
onSuccess(input) | ||
} catch (e: IllegalArgumentException) { | ||
onFailure() | ||
} catch (e: NullPointerException) { | ||
onFailure() | ||
} | ||
} |