mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-229792 Support record declaration in complete statement
GitOrigin-RevId: f0257fa34cd4bc8e5445f8f4bc417747790c2538
This commit is contained in:
committed by
intellij-monorepo-bot
parent
42b6965a5d
commit
abdf1f601d
+12
-2
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.editorActions.smartEnter;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiRecordComponent;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
@@ -12,13 +13,22 @@ import com.intellij.util.IncorrectOperationException;
|
||||
public class MissingClassBodyFixer implements Fixer {
|
||||
@Override
|
||||
public void apply(Editor editor, JavaSmartEnterProcessor processor, PsiElement psiElement) throws IncorrectOperationException {
|
||||
if (psiElement instanceof PsiRecordComponent) {
|
||||
psiElement = ((PsiRecordComponent)psiElement).getContainingClass();
|
||||
}
|
||||
if (!(psiElement instanceof PsiClass) || psiElement instanceof PsiTypeParameter) return;
|
||||
PsiClass psiClass = (PsiClass) psiElement;
|
||||
|
||||
if (psiClass.getLBrace() == null) {
|
||||
int offset = psiClass.getTextRange().getEndOffset();
|
||||
editor.getDocument().insertString(offset, "{\n}");
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
if (psiClass.isRecord() && psiClass.getRecordHeader() == null) {
|
||||
editor.getDocument().insertString(offset, "() {}");
|
||||
editor.getCaretModel().moveToOffset(offset + 1);
|
||||
processor.setSkipEnter(true);
|
||||
} else {
|
||||
editor.getDocument().insertString(offset, "{\n}");
|
||||
editor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
public record Record<caret>
|
||||
@@ -0,0 +1,2 @@
|
||||
public record Record(int x<caret>) {
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
public record Record(int x<caret>)
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
public record Record(int x) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
public record Record(int x) {
|
||||
<caret>
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
public record Record(<caret>) {
|
||||
}
|
||||
@@ -189,6 +189,9 @@ public class CompleteStatementTest extends EditorActionTestCase {
|
||||
public void testModuleInfo() { doTest(); }
|
||||
public void testDoubleFieldDeclaration() { doTest(); }
|
||||
public void testAddTernaryColon() { doTest(); }
|
||||
public void testRecord() { doTest(); }
|
||||
public void testRecordWithComponent() { doTest(); }
|
||||
public void testRecordWithComponentNoBody() { doTest(); }
|
||||
|
||||
private void doTestBracesNextLineStyle() {
|
||||
myJavaSettings.BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
|
||||
|
||||
Reference in New Issue
Block a user