rename wrong ref by Shift-F6 (IDEA-61734)

This commit is contained in:
anna
2011-04-17 19:56:13 +02:00
parent b1966bfcb7
commit f42960991c
6 changed files with 150 additions and 26 deletions

View File

@@ -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);
}
}
}