[java-inspections] IDEA-374865 ClassCanBeRecord: fix this not being considered a reference to containing class

In response to IJ-CR-167896

GitOrigin-RevId: e1046f37f326ea127d14d27d332001800e46d327
This commit is contained in:
Bartek Pacia
2025-07-08 21:40:33 +00:00
committed by intellij-monorepo-bot
parent 3c61fc793b
commit da203f41d0
2 changed files with 21 additions and 0 deletions
@@ -252,6 +252,12 @@ final class ConstructorBodyProcessor {
if (expression == null) return false;
Ref<Boolean> hasReferenceToClassUnderConstruction = new Ref<>(false);
expression.accept(new JavaRecursiveElementWalkingVisitor() {
@Override
public void visitThisExpression(PsiThisExpression expression) {
super.visitThisExpression(expression);
hasReferenceToClassUnderConstruction.set(true);
}
@Override
public void visitReferenceExpression(PsiReferenceExpression expression) {
super.visitReferenceExpression(expression);
@@ -0,0 +1,15 @@
// "Convert to record class" "false"
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(this); // javac error: "cannot reference this before supertype constructor has been called"
this(person.name, person.age);
}
}