mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Java: fix inappropriate quick-fix for bodyless methods in record (IDEA-299166)
fixes error message as well GitOrigin-RevId: 2b9d54fa48b282dc003753645237ebfdb50c0d01
This commit is contained in:
committed by
intellij-monorepo-bot
parent
741b740e5d
commit
24557b8338
+5
-3
@@ -1300,12 +1300,14 @@ public final class HighlightMethodUtil {
|
||||
int start = method.getModifierList().getTextRange().getStartOffset();
|
||||
int end = Math.max(start, method.getTextRange().getEndOffset());
|
||||
|
||||
String description = JavaErrorBundle.message("missing.method.body");
|
||||
boolean abstractAllowed = !aClass.isRecord() && !method.isConstructor() && !(aClass instanceof PsiAnonymousClass);
|
||||
String description = abstractAllowed
|
||||
? JavaErrorBundle.message("missing.method.body.or.declare.abstract")
|
||||
: JavaErrorBundle.message("missing.method.body");
|
||||
errorResult = HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(start, end).descriptionAndTooltip(description);
|
||||
IntentionAction action = QuickFixFactory.getInstance().createAddMethodBodyFix(method);
|
||||
errorResult.registerFix(action, null, null, null, null);
|
||||
if (HighlightUtil.getIncompatibleModifier(PsiModifier.ABSTRACT, method.getModifierList()) == null &&
|
||||
!(aClass instanceof PsiAnonymousClass)) {
|
||||
if (abstractAllowed && HighlightUtil.getIncompatibleModifier(PsiModifier.ABSTRACT, method.getModifierList()) == null) {
|
||||
final List<IntentionAction> actions =
|
||||
JvmElementActionFactories.createModifierActions(method, MemberRequestsKt.modifierRequest(JvmModifier.ABSTRACT, true));
|
||||
QuickFixAction.registerQuickFixActions(errorResult, null, actions);
|
||||
|
||||
@@ -158,7 +158,8 @@ ambiguous.method.call=Ambiguous method call: both ''{0}'' and ''{1}'' match
|
||||
ambiguous.reference=Reference to ''{0}'' is ambiguous, both ''{1}'' and ''{2}'' match
|
||||
cannot.resolve.method=Cannot resolve method ''{0}''
|
||||
ambiguous.method.call.no.match=Cannot resolve method ''{0}'' in ''{1}''
|
||||
missing.method.body=Missing method body, or declare abstract
|
||||
missing.method.body.or.declare.abstract=Method body or 'abstract' modifier expected
|
||||
missing.method.body=Method body expected
|
||||
abstract.method.in.non.abstract.class=Abstract method in non-abstract class
|
||||
missing.return.type=Invalid method declaration; return type required
|
||||
duplicate.method=''{0}'' is already defined in ''{1}''
|
||||
|
||||
+8
-3
@@ -1,11 +1,11 @@
|
||||
// abstract methods
|
||||
class a {
|
||||
<error descr="Missing method body, or declare abstract">void f();</error>
|
||||
<error descr="Method body or 'abstract' modifier expected">void f();</error>
|
||||
|
||||
}
|
||||
abstract class c1 {
|
||||
abstract void f1();
|
||||
<error descr="Missing method body, or declare abstract">int f2();</error>
|
||||
<error descr="Method body or 'abstract' modifier expected">int f2();</error>
|
||||
}
|
||||
|
||||
interface ff {
|
||||
@@ -80,7 +80,11 @@ abstract class cc2 extends cc1 {
|
||||
abstract protected void f(int i);
|
||||
}
|
||||
class cc3 extends cc2 {
|
||||
public void f(int i) {}
|
||||
public void f(int i) {
|
||||
new Object() {
|
||||
<error descr="Method body expected">void x();</error>
|
||||
};
|
||||
}
|
||||
}
|
||||
///////////////
|
||||
interface MyComparator {
|
||||
@@ -89,6 +93,7 @@ interface MyComparator {
|
||||
boolean equals(java.lang.Object object);
|
||||
}
|
||||
class MyComparatorImpl implements MyComparator {
|
||||
<error descr="Method body expected">MyComparatorImpl();</error>
|
||||
public int compare(Object o, Object o1) {
|
||||
new MyComparator() {
|
||||
public int compare(Object o, Object o1) {
|
||||
|
||||
+3
@@ -80,4 +80,7 @@ record ExtendsRecordExplicitly() <error descr="'extends' not allowed on record">
|
||||
|
||||
record AbstractMethod() {
|
||||
<error descr="Abstract method in non-abstract class">abstract</error> void f();
|
||||
}
|
||||
record MethodWithoutBody() {
|
||||
<error descr="Method body expected">void x();</error>
|
||||
}
|
||||
@@ -370,7 +370,7 @@ class CtorTest {
|
||||
System.out.println(test.get());
|
||||
}
|
||||
|
||||
<error descr="Missing method body, or declare abstract">CtorTest(String noBody);</error>
|
||||
<error descr="Method body expected">CtorTest(String noBody);</error>
|
||||
|
||||
void something() {
|
||||
test = Optional.empty();
|
||||
|
||||
Reference in New Issue
Block a user