Introduce action to add missing when branches on sealed class
Made via diagnostics NON_EXHAUSTIVE_WHEN_FOR_SEALED_CLASS with INFO severity and quick-fix So #KT-17580 Fixed
This commit is contained in:
committed by
Mikhail Glukhikh
parent
1072495001
commit
e30b9758f4
@@ -250,7 +250,7 @@ private class ElementAnnotator(private val element: PsiElement,
|
||||
}
|
||||
)
|
||||
}
|
||||
Severity.INFO -> return // Do nothing
|
||||
Severity.INFO -> AnnotationPresentationInfo(ranges, highlightType = ProblemHighlightType.INFORMATION)
|
||||
}
|
||||
|
||||
setUpAnnotations(diagnostics, presentationInfo)
|
||||
@@ -298,7 +298,7 @@ private class AnnotationPresentationInfo(
|
||||
holder.createWarningAnnotation(range, defaultMessage)
|
||||
}
|
||||
}
|
||||
else -> throw IllegalArgumentException("Only ERROR and WARNING diagnostics are supported")
|
||||
Severity.INFO -> holder.createInfoAnnotation(range, defaultMessage)
|
||||
}
|
||||
|
||||
annotation.tooltip = getMessage(diagnostic)
|
||||
|
||||
@@ -241,6 +241,8 @@ class QuickFixRegistrar : QuickFixContributor {
|
||||
REDUNDANT_ELSE_IN_WHEN.registerFactory(RemoveWhenElseBranchFix)
|
||||
NON_EXHAUSTIVE_WHEN.registerFactory(AddWhenElseBranchFix)
|
||||
NON_EXHAUSTIVE_WHEN.registerFactory(AddWhenRemainingBranchesFix)
|
||||
NON_EXHAUSTIVE_WHEN_ON_SEALED_CLASS.registerFactory(AddWhenElseBranchFix)
|
||||
NON_EXHAUSTIVE_WHEN_ON_SEALED_CLASS.registerFactory(AddWhenRemainingBranchesFix)
|
||||
BREAK_OR_CONTINUE_IN_WHEN.registerFactory(AddLoopLabelFix)
|
||||
|
||||
NO_TYPE_ARGUMENTS_ON_RHS.registerFactory(AddStarProjectionsFix.IsExpressionFactory)
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Add remaining branches" "true"
|
||||
// ERROR: Unresolved reference: TODO
|
||||
// ERROR: Unresolved reference: TODO
|
||||
// ERROR: Unresolved reference: TODO
|
||||
sealed class Variant {
|
||||
object Singleton : Variant()
|
||||
|
||||
class Something(val x: Int) : Variant()
|
||||
|
||||
object Another : Variant()
|
||||
}
|
||||
fun test(v: Variant?) {
|
||||
wh<caret>en(v) {
|
||||
Variant.Singleton -> "s"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Add remaining branches" "true"
|
||||
// ERROR: Unresolved reference: TODO
|
||||
// ERROR: Unresolved reference: TODO
|
||||
// ERROR: Unresolved reference: TODO
|
||||
sealed class Variant {
|
||||
object Singleton : Variant()
|
||||
|
||||
class Something(val x: Int) : Variant()
|
||||
|
||||
object Another : Variant()
|
||||
}
|
||||
fun test(v: Variant?) {
|
||||
when(v) {
|
||||
Variant.Singleton -> "s"
|
||||
is Variant.Something -> TODO()
|
||||
Variant.Another -> TODO()
|
||||
null -> TODO()
|
||||
}
|
||||
}
|
||||
@@ -10957,6 +10957,12 @@ public class QuickFixTestGenerated extends AbstractQuickFixTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("addRemainingBranchesSealedStatement.kt")
|
||||
public void testAddRemainingBranchesSealedStatement() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/quickfix/when/addRemainingBranchesSealedStatement.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
public void testAllFilesPresentInWhen() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/when"), Pattern.compile("^([\\w\\-_]+)\\.kt$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user