Java: add test for renaming record component with non-physical accessor (IJ-CR-157393)

GitOrigin-RevId: e88f2f4fc950c169d932220c48148a82e4c5bd34
This commit is contained in:
Bas Leijdekkers
2025-03-13 10:50:04 +00:00
committed by intellij-monorepo-bot
parent 2905a9b992
commit a36f063456
3 changed files with 36 additions and 0 deletions
@@ -0,0 +1,7 @@
package some.internal.pkg;
record Hello(
int hello<caret>,
int bar,
int baz
) {}
@@ -0,0 +1,7 @@
package some.internal.pkg;
record Hello(
int foo<caret>,
int bar,
int baz
) {}
@@ -4,12 +4,15 @@ package com.intellij.java.refactoring;
import com.intellij.JavaTestUtil;
import com.intellij.application.options.CodeStyle;
import com.intellij.codeInsight.TargetElementUtil;
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
import com.intellij.codeInsight.template.impl.TemplateState;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.actionSystem.DataContext;
import com.intellij.openapi.editor.ex.EditorEx;
import com.intellij.pom.java.JavaFeature;
import com.intellij.psi.PsiElement;
import com.intellij.refactoring.rename.*;
import com.intellij.refactoring.rename.inplace.MemberInplaceRenameHandler;
import com.intellij.refactoring.rename.naming.AutomaticRenamerFactory;
import com.intellij.testFramework.IdeaTestUtil;
import org.jetbrains.annotations.NonNls;
@@ -112,6 +115,25 @@ public class RenameFieldTest extends LightRefactoringTestCase {
doTest("baz");
}
public void testRecordNonPhysicalAccessor() {
String testName = getTestName(false);
configureByFile("/refactoring/renameField/before" + testName + ".java");
TemplateManagerImpl.setTemplateTesting(getTestRootDisposable());
PsiElement element = TargetElementUtil.findTargetElement(getEditor(), TargetElementUtil.ELEMENT_NAME_ACCEPTED);
assertNotNull(element);
try {
new MemberInplaceRenameHandler().doRename(element, getEditor(), null);
type("hello");
}
finally {
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
assertNotNull(state);
state.gotoEnd(false);
}
checkResultByFile("/refactoring/renameField/after" + testName + ".java");
}
public void testFieldOnlyInImplicitClass() {
IdeaTestUtil.withLevel(getModule(), JavaFeature.IMPLICIT_CLASSES.getMinimumLevel(), () -> {
String suffix = getTestName(false);