mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[java-inspections] IDEA-374865 ClassCanBeRecord: fix more edge cases found by Bas
In response to IJ-CR-167896 GitOrigin-RevId: 5c472609a72edc206ac42486fc0f6ecb25ed09b6
This commit is contained in:
committed by
intellij-monorepo-bot
parent
92d629b83c
commit
b7ba10b29b
+14
-13
@@ -5,6 +5,7 @@ import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.pom.java.JavaFeature;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.JavaPsiConstructorUtil;
|
||||
@@ -257,6 +258,11 @@ final class ConstructorBodyProcessor {
|
||||
stopWalking();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitClass(PsiClass aClass) {
|
||||
// Empty on purpose.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(PsiThisExpression expression) {
|
||||
super.visitThisExpression(expression);
|
||||
@@ -266,6 +272,11 @@ final class ConstructorBodyProcessor {
|
||||
@Override
|
||||
public void visitReferenceExpression(PsiReferenceExpression expression) {
|
||||
super.visitReferenceExpression(expression);
|
||||
|
||||
if (expression.getQualifier() != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiElement resolved = expression.resolve();
|
||||
if (resolved == null) {
|
||||
markInvalid();
|
||||
@@ -273,20 +284,10 @@ final class ConstructorBodyProcessor {
|
||||
}
|
||||
|
||||
if (resolved instanceof PsiField field && !field.hasModifierProperty(STATIC) && field.getContainingClass() == containingClass) {
|
||||
if (expression.getQualifier() == null) {
|
||||
markInvalid();
|
||||
}
|
||||
else {
|
||||
// There is a qualifier, and it is not "this".
|
||||
}
|
||||
markInvalid();
|
||||
}
|
||||
else if (resolved instanceof PsiMethod method) {
|
||||
if (method.hasModifierProperty(STATIC)) return;
|
||||
if (method.getContainingClass() == containingClass) {
|
||||
markInvalid();
|
||||
return;
|
||||
}
|
||||
if (containingClass.findMethodBySignature(method, true) != null) {
|
||||
else if (resolved instanceof PsiMethod method && !method.hasModifierProperty(STATIC)) {
|
||||
if (InheritanceUtil.isInheritorOrSelf(containingClass, method.getContainingClass(), true)) {
|
||||
markInvalid();
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
record Person(String name, int age) {
|
||||
|
||||
Person(Person person) {
|
||||
new Object() {{
|
||||
hashCode();
|
||||
}};
|
||||
this(person.name, person.age);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
record Person(String name, int age) {
|
||||
|
||||
Person(Person person) {
|
||||
System.out.println(person.hashCode());
|
||||
this(person.name, person.age);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
record Person(String name, int age) {
|
||||
Person {
|
||||
System.out.println("".isEmpty());
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
class Person<caret> {
|
||||
final String name;
|
||||
final int age;
|
||||
|
||||
Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
Person(Person person) {
|
||||
new Object() {{
|
||||
hashCode();
|
||||
}};
|
||||
this(person.name, person.age);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
class Person<caret> {
|
||||
final String name;
|
||||
final int age;
|
||||
|
||||
Person(String name, int age) {
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
Person(Person person) {
|
||||
System.out.println(person.hashCode());
|
||||
this(person.name, person.age);
|
||||
}
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
// "Convert to record class" "true-preview"
|
||||
class Person<caret> {
|
||||
final String name;
|
||||
final int age;
|
||||
|
||||
Person(String name, int age) {
|
||||
System.out.println("".isEmpty());
|
||||
this.name = name;
|
||||
this.age = age;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user