diff --git a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordFix.java b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordFix.java index 37ad7609f897..f9b18960f9ca 100644 --- a/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordFix.java +++ b/java/java-impl-inspections/src/com/intellij/codeInspection/classCanBeRecord/ConvertToRecordFix.java @@ -1,4 +1,4 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.codeInspection.classCanBeRecord; import com.intellij.codeInsight.AnnotationTargetUtil; @@ -294,7 +294,9 @@ public class ConvertToRecordFix extends InspectionGadgetsFix { recordStyleNaming = true; break; } - if (mySuggestAccessorsRenaming && fieldName.equals(PropertyUtilBase.getPropertyNameByGetter(psiMethod))) { + if (mySuggestAccessorsRenaming && fieldName.equals(PropertyUtilBase.getPropertyNameByGetter(psiMethod)) && + !ContainerUtil.exists(psiMethod.findDeepestSuperMethods(), + superMethod -> superMethod instanceof PsiCompiledElement || superMethod instanceof SyntheticElement)) { backingField = field; break; } diff --git a/java/java-tests/testData/inspection/classCanBeRecord/afterInheritCompiledClass.java b/java/java-tests/testData/inspection/classCanBeRecord/afterInheritCompiledClass.java new file mode 100644 index 000000000000..dbbe9207c565 --- /dev/null +++ b/java/java-tests/testData/inspection/classCanBeRecord/afterInheritCompiledClass.java @@ -0,0 +1,23 @@ +// "Convert to record class" "true-preview" +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +class Outer { + private record ParameterizedTypeImpl(Type rawType, Type... typeArguments) implements ParameterizedType { + + @Override + public Type[] getActualTypeArguments() { + return typeArguments; + } + + @Override + public Type getRawType() { + return rawType; + } + + @Override + public Type getOwnerType() { + return null; + } + } +} \ No newline at end of file diff --git a/java/java-tests/testData/inspection/classCanBeRecord/beforeInheritCompiledClass.java b/java/java-tests/testData/inspection/classCanBeRecord/beforeInheritCompiledClass.java new file mode 100644 index 000000000000..138fe0ec2d1f --- /dev/null +++ b/java/java-tests/testData/inspection/classCanBeRecord/beforeInheritCompiledClass.java @@ -0,0 +1,31 @@ +// "Convert to record class" "true-preview" +import java.lang.reflect.ParameterizedType; +import java.lang.reflect.Type; + +class Outer { + private static class ParameterizedTypeImpl implements ParameterizedType { + private final Type rawType; + + private final Type[] typeArguments; + + public ParameterizedTypeImpl(Type rawType, Type... typeArguments) { + this.rawType = rawType; + this.typeArguments = typeArguments; + } + + @Override + public Type[] getActualTypeArguments() { + return typeArguments; + } + + @Override + public Type getRawType() { + return rawType; + } + + @Override + public Type getOwnerType() { + return null; + } + } +} \ No newline at end of file