mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 20:39:40 +07:00
IDEA-247279 - fixed the choice of suggested methods when records implement some interface
GitOrigin-RevId: 1a452fdf44fe0ca20935b9129565117ab0d6a85c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
ab344fd654
commit
23003595bd
@@ -12,11 +12,14 @@ import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.util.NlsContexts;
|
||||
import com.intellij.openapi.util.NotNullLazyValue;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.infos.CandidateInfo;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -90,7 +93,15 @@ public final class JavaOverrideImplementMemberChooser extends MemberChooser<PsiM
|
||||
if (onlyPrimary.length == 0) {
|
||||
javaOverrideImplementMemberChooser.selectElements(new ClassMember[] {all[0]});
|
||||
} else {
|
||||
javaOverrideImplementMemberChooser.selectElements(onlyPrimary);
|
||||
PsiClass currClass = ObjectUtils.tryCast(aClass, PsiClass.class);
|
||||
if (currClass != null && currClass.isRecord()) {
|
||||
PsiMethodMember[] toImplementMembers = ContainerUtil
|
||||
.filter(onlyPrimary, m -> !OverrideImplementExploreUtil.belongsToRecord(m.getElement()))
|
||||
.toArray(new PsiMethodMember[0]);
|
||||
javaOverrideImplementMemberChooser.selectElements(ArrayUtil.isEmpty(toImplementMembers) ? onlyPrimary : toImplementMembers);
|
||||
} else {
|
||||
javaOverrideImplementMemberChooser.selectElements(onlyPrimary);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -169,7 +169,11 @@ public class OverrideImplementExploreUtil {
|
||||
return isDefaultMethod(aClass, abstractOne) ||
|
||||
// abstract methods from java.lang.Record (equals/hashCode/toString) are implicitly implemented in subclasses
|
||||
// so it could be reasonable to expect them in 'override' method dialog
|
||||
CommonClassNames.JAVA_LANG_RECORD.equals(Objects.requireNonNull(abstractOne.getContainingClass()).getQualifiedName());
|
||||
belongsToRecord(abstractOne);
|
||||
}
|
||||
|
||||
static boolean belongsToRecord(@NotNull PsiMethod method) {
|
||||
return CommonClassNames.JAVA_LANG_RECORD.equals(Objects.requireNonNull(method.getContainingClass()).getQualifiedName());
|
||||
}
|
||||
|
||||
private static boolean preferLeftForImplement(@NotNull PsiMethod left, @NotNull PsiMethod right) {
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
record R() implements Nameable, Sizable {
|
||||
@Override
|
||||
public String name() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lastName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
interface Nameable {
|
||||
String name();
|
||||
|
||||
String lastName();
|
||||
}
|
||||
|
||||
interface Sizable {
|
||||
int size();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
record R() implements Nameable, Sizable {
|
||||
<caret>
|
||||
}
|
||||
|
||||
interface Nameable {
|
||||
String name();
|
||||
|
||||
String lastName();
|
||||
}
|
||||
|
||||
interface Sizable {
|
||||
int size();
|
||||
}
|
||||
@@ -39,6 +39,8 @@ class OverrideImplementTest extends LightJavaCodeInsightFixtureTestCase {
|
||||
|
||||
void testImplementRecordMethods() { addRecordClass();doTest(true) }
|
||||
|
||||
void testImplementInterfaceMethodsInRecord() { addRecordClass();doTest(true) }
|
||||
|
||||
void testOverrideRecordMethods() { addRecordClass();doTest(false) }
|
||||
|
||||
void testImplementExtensionMethods() { doTest(true) }
|
||||
|
||||
Reference in New Issue
Block a user