mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-08 14:57:35 +07:00
rename wrong ref by Shift-F6 (IDEA-61734)
This commit is contained in:
@@ -2,12 +2,24 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.codeInsight.template.TemplateManager;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.lang.java.JavaRefactoringSupportProvider;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.introduceField.InplaceIntroduceFieldPopup;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.refactoring.rename.RenameWrongRefHandler;
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestUtil;
|
||||
import sun.misc.Ref;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
@@ -85,4 +97,38 @@ public class RenameLocalTest extends LightCodeInsightTestCase {
|
||||
|
||||
checkResultByFile(BASE_PATH + getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testRenameWrongRef() throws Exception {
|
||||
doRenameWrongRef("i");
|
||||
}
|
||||
|
||||
private void doRenameWrongRef(final String newName) throws Exception {
|
||||
final String name = getTestName(true);
|
||||
configureByFile(BASE_PATH + name + ".java");
|
||||
|
||||
final TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(getProject());
|
||||
try {
|
||||
templateManager.setTemplateTesting(true);
|
||||
|
||||
new RenameWrongRefHandler().invoke(getProject(), getEditor(), getFile(), null);
|
||||
|
||||
final TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
|
||||
assert state != null;
|
||||
final TextRange range = state.getCurrentVariableRange();
|
||||
assert range != null;
|
||||
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
getEditor().getDocument().replaceString(range.getStartOffset(), range.getEndOffset(), newName);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
state.gotoEnd(false);
|
||||
checkResultByFile(BASE_PATH + name + "_after.java");
|
||||
}
|
||||
finally {
|
||||
templateManager.setTemplateTesting(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user