mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] Support NOT_A_LOOP_LABEL diagnostic when creating CreateLabel fix
KTIJ-29594 K2 IDE: Port CreateLabelFix GitOrigin-RevId: d40f019fdc3cd5a309b02f672b99bcea52b86e2c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
bb350f9546
commit
dac2430b1a
+16
-4
@@ -8,11 +8,23 @@ import org.jetbrains.kotlin.idea.quickfix.CreateLabelFix.Companion.getContaining
|
||||
import org.jetbrains.kotlin.idea.quickfix.CreateLabelFix.Companion.getContainingLoops
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
|
||||
internal object CreateLabelFixFactory {
|
||||
|
||||
val createLabelFixFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.UnresolvedLabel ->
|
||||
internal object CreateLabelFixFactories {
|
||||
|
||||
val unresolvedLabelFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.UnresolvedLabel ->
|
||||
val labelReferenceExpression = diagnostic.psi as? KtLabelReferenceExpression ?: return@IntentionBased emptyList()
|
||||
return@IntentionBased getFixes(labelReferenceExpression)
|
||||
}
|
||||
|
||||
val notALoopLabelFactory = KotlinQuickFixFactory.IntentionBased { diagnostic: KaFirDiagnostic.NotALoopLabel ->
|
||||
val breakOrContinueExpression =
|
||||
diagnostic.psi as? KtBreakExpression ?: diagnostic.psi as? KtContinueExpression ?: return@IntentionBased emptyList()
|
||||
|
||||
val labelReferenceExpression =
|
||||
breakOrContinueExpression.getTargetLabel() as? KtLabelReferenceExpression ?: return@IntentionBased emptyList()
|
||||
return@IntentionBased getFixes(labelReferenceExpression)
|
||||
}
|
||||
|
||||
private fun getFixes(labelReferenceExpression: KtLabelReferenceExpression): List<CreateLabelFix> {
|
||||
val fixes = when ((labelReferenceExpression.parent as? KtContainerNode)?.parent) {
|
||||
is KtBreakExpression, is KtContinueExpression -> {
|
||||
if (labelReferenceExpression.getContainingLoops().any()) {
|
||||
@@ -32,7 +44,7 @@ internal object CreateLabelFixFactory {
|
||||
|
||||
else -> emptyList()
|
||||
}
|
||||
return@IntentionBased fixes
|
||||
return fixes
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -124,7 +124,8 @@ class KotlinK2QuickFixRegistrar : KotlinQuickFixRegistrar() {
|
||||
registerFactory(RenameModToRemFixFactory.deprecatedBinaryModFactory)
|
||||
registerFactory(RenameModToRemFixFactory.forbiddenBinaryModFactory)
|
||||
registerFactory(AddEmptyArgumentListFixFactory.addEmptyArgumentListFixFactory)
|
||||
registerFactory(KaFirDiagnostic.UnresolvedLabel::class, CreateLabelFixFactory.createLabelFixFactory)
|
||||
registerFactory(KaFirDiagnostic.UnresolvedLabel::class, CreateLabelFixFactories.unresolvedLabelFactory)
|
||||
registerFactory(KaFirDiagnostic.NotALoopLabel::class, CreateLabelFixFactories.notALoopLabelFactory)
|
||||
registerFactory(AddDefaultConstructorFixFactory.addDefaultConstructorFixFactory)
|
||||
registerFactory(MakeClassAnAnnotationClassFixFactory.makeClassAnAnnotationClassFixFactory)
|
||||
registerFactory(WrongLongSuffixFixFactory.changeToCorrectLongSuffix)
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
/* IGNORE_K2 */
|
||||
// Remove this ignoring after KT-69829 is fixed
|
||||
|
||||
// "Create label foo@" "true"
|
||||
|
||||
fun test() {
|
||||
|
||||
Reference in New Issue
Block a user