mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-374865 ClassCanBeRecord: fix edge case with calls to super methods
Now quick-fix is not shown when, in the class constructor, a method from superclass/superinterface is called before the class is ready for that. Basically, respect javac behavior. In response to IJ-CR-167896 GitOrigin-RevId: 421fc995c478ec20e39292ed02a32cb249b6398b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
944a6f1871
commit
90c2e9dc98
+9
-4
@@ -265,10 +265,15 @@ final class ConstructorBodyProcessor {
|
||||
if (resolved instanceof PsiField field && !field.hasModifierProperty(STATIC) && field.getContainingClass() == containingClass) {
|
||||
hasReferenceToClassUnderConstruction.set(true);
|
||||
}
|
||||
else if (resolved instanceof PsiMethod method &&
|
||||
!method.hasModifierProperty(STATIC) &&
|
||||
method.getContainingClass() == containingClass) {
|
||||
hasReferenceToClassUnderConstruction.set(true);
|
||||
else if (resolved instanceof PsiMethod method) {
|
||||
if (method.hasModifierProperty(STATIC)) return;
|
||||
if (method.getContainingClass() == containingClass) {
|
||||
hasReferenceToClassUnderConstruction.set(true);
|
||||
return;
|
||||
}
|
||||
if (containingClass.findMethodBySignature(method, true) != null) {
|
||||
hasReferenceToClassUnderConstruction.set(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
// "Convert to record class" "false"
|
||||
interface LivingAndBreathing {
|
||||
default void performBackflip() {
|
||||
System.out.println("Watch out, I'm gonna do a backflip");
|
||||
}
|
||||
}
|
||||
|
||||
class Person<caret> implements LivingAndBreathing {
|
||||
final String name;
|
||||
final int age;
|
||||
|
||||
Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
Person(String name) {
|
||||
performBackflip(); // javac error: "cannot reference performBackflip() before supertype constructor has been called"
|
||||
this(name, 0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user