Add inspection to replace not-null assertion with elvis return

#KT-30381 Fixed
This commit is contained in:
Toshiaki Kameyama
2019-03-12 12:05:00 +09:00
committed by Dmitry Gridin
parent 1c0c01725b
commit dffcfdc02f
24 changed files with 282 additions and 0 deletions
@@ -3355,6 +3355,15 @@
language="kotlin"
/>
<localInspection implementationClass="org.jetbrains.kotlin.idea.inspections.ReplaceNotNullAssertionWithElvisReturnInspection"
displayName="Replace '!!' with '?: return'"
groupPath="Kotlin"
groupName="Style issues"
enabledByDefault="false"
level="WEAK WARNING"
language="kotlin"
/>
<referenceImporter implementation="org.jetbrains.kotlin.idea.quickfix.KotlinReferenceImporter"/>
<fileType.fileViewProviderFactory filetype="KJSM" implementationClass="com.intellij.psi.ClassFileViewProviderFactory"/>
@@ -0,0 +1,13 @@
<html>
<body>
This inspection reports not-null assertion (<b>!!</b>) calls that can be replaced with elvis and return (<b>?: return</b>). For example:
<br /><br />
<pre>
val number: Int? = 42
fun foo() {
val a = number!! // Replace '!!' with '?: return'
println(1 + a)
}
</pre>
</body>
</html>