ReplaceGuardClause inspection: check contracts availability
This commit is contained in:
committed by
Mikhail Glukhikh
parent
8cbcb66197
commit
2ca0056cd0
+4
@@ -8,10 +8,12 @@ package org.jetbrains.kotlin.idea.inspections
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyze
|
||||
import org.jetbrains.kotlin.idea.core.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.core.replaced
|
||||
import org.jetbrains.kotlin.idea.intentions.callExpression
|
||||
import org.jetbrains.kotlin.idea.project.languageVersionSettings
|
||||
import org.jetbrains.kotlin.idea.util.CommentSaver
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -44,6 +46,8 @@ class ReplaceGuardClauseWithFunctionCallInspection : AbstractApplicabilityBasedI
|
||||
element.getKotlinFunction()?.let { "Replace with '${it.functionName}()' call" } ?: defaultFixText
|
||||
|
||||
override fun isApplicable(element: KtIfExpression): Boolean {
|
||||
val languageVersionSettings = element.languageVersionSettings
|
||||
if (!languageVersionSettings.supportsFeature(LanguageFeature.UseReturnsEffect)) return false
|
||||
if (element.condition == null) return false
|
||||
val call = element.getCallExpression() ?: return false
|
||||
val calleeText = call.calleeExpression?.text ?: return false
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// PROBLEM: none
|
||||
// WITH_RUNTIME
|
||||
// LANGUAGE_VERSION: 1.2
|
||||
fun test(foo: Int?) {
|
||||
<caret>if (foo == null) {
|
||||
throw IllegalArgumentException("test")
|
||||
}
|
||||
bar(foo)
|
||||
}
|
||||
|
||||
fun bar(i: Int) {}
|
||||
+5
@@ -8924,6 +8924,11 @@ public class LocalInspectionTestGenerated extends AbstractLocalInspectionTest {
|
||||
runTest("idea/testData/inspectionsLocal/replaceGuardClauseWithFunctionCall/notTargetException.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("version12.kt")
|
||||
public void testVersion12() throws Exception {
|
||||
runTest("idea/testData/inspectionsLocal/replaceGuardClauseWithFunctionCall/version12.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/inspectionsLocal/replaceGuardClauseWithFunctionCall/check")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user