[intention-preview] Create record on record pattern: fix an exception when the record component pattern list is empty

IDEA-304933

GitOrigin-RevId: f0fe135f3bddf5e5705f76de8ebe095543bd18a8
This commit is contained in:
Andrey Cherkasov
2022-10-28 16:40:46 +04:00
committed by intellij-monorepo-bot
parent e056e25116
commit d0c57ae46f
6 changed files with 46 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ import com.intellij.codeInsight.CodeInsightUtilCore;
import com.intellij.codeInsight.FileModificationService;
import com.intellij.codeInsight.daemon.QuickFixBundle;
import com.intellij.codeInsight.intention.preview.IntentionPreviewInfo;
import com.intellij.codeInsight.intention.preview.IntentionPreviewUtils;
import com.intellij.codeInsight.template.Template;
import com.intellij.codeInsight.template.TemplateBuilderImpl;
import com.intellij.codeInspection.util.IntentionName;
@@ -195,7 +196,7 @@ public class CreateInnerClassFromUsageFix extends CreateClassFromUsageBaseFix {
editor.getDocument().deleteString(textRange.getStartOffset(), textRange.getEndOffset());
CreateFromUsageBaseFix.startTemplate(editor, template, project, null, text);
}
else {
else if (!IntentionPreviewUtils.isPreviewElement(deconstructionList)) {
CodeInsightUtil.positionCursor(project, aClass.getContainingFile(), ObjectUtils.notNull(aClass.getNameIdentifier(), aClass));
}
}

View File

@@ -0,0 +1,12 @@
// "Create record 'EmptyBox'" "true-preview"
class Test {
void foo(Object obj) {
switch (obj) {
case EmptyBox() -> System.out.println( "Fill it up and send it back");
default -> {}
}
}
}
public record EmptyBox() {
}

View File

@@ -0,0 +1,9 @@
// "Create record 'EmptyBox'" "true-preview"
class Test {
void foo(Object obj) {
switch (obj) {
case Empty<caret>Box() -> System.out.println( "Fill it up and send it back");
default -> {}
}
}
}

View File

@@ -0,0 +1,12 @@
// "Create inner record 'EmptyBox'" "true-preview"
class Test {
void foo(Object obj) {
switch (obj) {
case EmptyBox() -> System.out.println( "Fill it up and send it back");
default -> {}
}
}
private record EmptyBox() {
}
}

View File

@@ -0,0 +1,9 @@
// "Create inner record 'EmptyBox'" "true-preview"
class Test {
void foo(Object obj) {
switch (obj) {
case Empty<caret>Box() -> System.out.println( "Fill it up and send it back");
default -> {}
}
}
}