mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-17 01:57:50 +07:00
IDEA-229694 Generate constructor for records: suggest generation of compact and canonical constructors
GitOrigin-RevId: 95e23c12711c867a1e1f41d42ee5f3cc87876b3d
This commit is contained in:
committed by
intellij-monorepo-bot
parent
39fc484b5d
commit
84c1a10be9
+21
@@ -0,0 +1,21 @@
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
record Test(final int foo, @Anno1 @Anno2 @Anno3 @Anno4 double bar) {
|
||||
public Test(int foo, @Anno2 @Anno3 @Anno4 double bar) {<caret>
|
||||
this.foo = foo;
|
||||
this.bar = bar;
|
||||
}
|
||||
|
||||
public int foo() {
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
@Target(ElementType.RECORD_COMPONENT)
|
||||
@interface Anno1 { }
|
||||
@Target({ElementType.RECORD_COMPONENT, ElementType.PARAMETER})
|
||||
@interface Anno2 { }
|
||||
@Target({ElementType.PARAMETER})
|
||||
@interface Anno3 { }
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface Anno4 { }
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
record R(int x, int y) {
|
||||
public R {<caret>
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
record Test(final int foo, @Anno1 @Anno2 @Anno3 @Anno4 double bar, String... varArg) {
|
||||
<caret>
|
||||
public int foo() {
|
||||
return foo;
|
||||
}
|
||||
}
|
||||
@Target(ElementType.RECORD_COMPONENT)
|
||||
@interface Anno1 { }
|
||||
@Target({ElementType.RECORD_COMPONENT, ElementType.PARAMETER})
|
||||
@interface Anno2 { }
|
||||
@Target({ElementType.PARAMETER})
|
||||
@interface Anno3 { }
|
||||
@Target({ElementType.TYPE_USE})
|
||||
@interface Anno4 { }
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
record R(int x, int y) {
|
||||
<caret>
|
||||
}
|
||||
@@ -19,17 +19,20 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.NullableNotNullManager;
|
||||
import com.intellij.codeInsight.generation.ClassMember;
|
||||
import com.intellij.codeInsight.generation.GenerateConstructorHandler;
|
||||
import com.intellij.codeInsight.generation.RecordConstructorMember;
|
||||
import com.intellij.java.codeInspection.DataFlowInspectionTest;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.LightProjectDescriptor;
|
||||
import com.intellij.testFramework.fixtures.LightJavaCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -104,10 +107,27 @@ public class GenerateConstructorTest extends LightJavaCodeInsightFixtureTestCase
|
||||
}
|
||||
|
||||
public void testNullableField() { doTest(); }
|
||||
|
||||
public void testRecordCompactConstructor() { doTestRecordConstructor(true); }
|
||||
|
||||
public void testRecordCanonicalConstructor() { doTestRecordConstructor(false); }
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
private void doTestRecordConstructor(boolean compact) {
|
||||
String name = getTestName(false);
|
||||
myFixture.configureByFile("before" + name + ".java");
|
||||
new GenerateConstructorHandler() {
|
||||
@Nullable
|
||||
@Override
|
||||
protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
|
||||
return new ClassMember[]{new RecordConstructorMember(aClass, compact)};
|
||||
}
|
||||
}.invoke(getProject(), getEditor(), getFile());
|
||||
myFixture.checkResultByFile("after" + name + ".java");
|
||||
}
|
||||
|
||||
private void doTest(boolean preSelect) {
|
||||
String name = getTestName(false);
|
||||
|
||||
Reference in New Issue
Block a user