mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
records: rename parameter names of canonical constructors together with components
IDEA-CR-57849 GitOrigin-RevId: 6d820e056aa4bd37798b9a873b8d20c6adc79b9b
This commit is contained in:
committed by
intellij-monorepo-bot
parent
dd9b0bbfbc
commit
2ec87504ff
+16
-4
@@ -14,6 +14,7 @@ import com.intellij.psi.codeStyle.VariableKind;
|
||||
import com.intellij.psi.controlFlow.ControlFlowUtil;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.util.JavaPsiRecordUtil;
|
||||
import com.intellij.psi.util.PropertyUtilBase;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
@@ -133,11 +134,22 @@ public class RenameJavaVariableProcessor extends RenameJavaMemberProcessor {
|
||||
if (element instanceof PsiRecordComponent) {
|
||||
PsiClass containingClass = ((PsiRecordComponent)element).getContainingClass();
|
||||
if (containingClass != null) {
|
||||
PsiMethod explicitGetter = ContainerUtil
|
||||
.find(containingClass.findMethodsByName(((PsiRecordComponent)element).getName(), false), m -> m.getParameters().length == 0);
|
||||
String name = ((PsiRecordComponent)element).getName();
|
||||
if (name != null) {
|
||||
PsiMethod explicitGetter = ContainerUtil
|
||||
.find(containingClass.findMethodsByName(name, false), m -> m.getParameters().length == 0);
|
||||
|
||||
if (explicitGetter != null) {
|
||||
addOverriddenAndImplemented(explicitGetter, newName, null, newName, JavaCodeStyleManager.getInstance(element.getProject()), allRenames);
|
||||
if (explicitGetter != null) {
|
||||
addOverriddenAndImplemented(explicitGetter, newName, null, newName, JavaCodeStyleManager.getInstance(element.getProject()), allRenames);
|
||||
}
|
||||
|
||||
PsiMethod canonicalConstructor = ContainerUtil.find(containingClass.getConstructors(), c -> JavaPsiRecordUtil.isExplicitCanonicalConstructor(c));
|
||||
if (canonicalConstructor != null) {
|
||||
PsiParameter parameter = ContainerUtil.find(canonicalConstructor.getParameterList().getParameters(), p -> name.equals(p.getName()));
|
||||
if (parameter != null) {
|
||||
allRenames.put(parameter, newName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
record Foo(int b<caret>ar, int foo) {
|
||||
public Foo(int bar, int foo) {
|
||||
this.bar = bar;
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
Foo(int bar) {
|
||||
this(bar, 0);
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
record Foo(int b<caret>az, int foo) {
|
||||
public Foo(int baz, int foo) {
|
||||
this.baz = baz;
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
Foo(int bar) {
|
||||
this(bar, 0);
|
||||
}
|
||||
}
|
||||
+4
@@ -46,6 +46,10 @@ public class LightRecordsHighlightingTest extends LightJavaCodeInsightFixtureTes
|
||||
doTestRename();
|
||||
}
|
||||
|
||||
public void testRenameWithCanonicalConstructor() {
|
||||
doTestRename();
|
||||
}
|
||||
|
||||
private void doTestRename() {
|
||||
doTest();
|
||||
myFixture.renameElementAtCaret("baz");
|
||||
|
||||
Reference in New Issue
Block a user