mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-16 22:51:17 +07:00
inplace introduce: do not touch next field type; fix introduce over local variable with initializer; tests
This commit is contained in:
@@ -24,6 +24,7 @@ import com.intellij.openapi.util.Pass;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer;
|
||||
import com.intellij.refactoring.introduceParameter.InplaceIntroduceParameterPopup;
|
||||
import com.intellij.refactoring.introduceParameter.IntroduceParameterHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
@@ -33,52 +34,28 @@ import org.jetbrains.annotations.NotNull;
|
||||
* User: anna
|
||||
* Date: 3/16/11
|
||||
*/
|
||||
public class InplaceIntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
public class InplaceIntroduceParameterTest extends AbstractInplaceIntroduceTest {
|
||||
|
||||
private static final String BASE_PATH = "/refactoring/inplaceIntroduceParameter/";
|
||||
|
||||
public void testReplaceAll() throws Exception {
|
||||
doTest(new Pass<InplaceIntroduceParameterPopup>() {
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(InplaceIntroduceParameterPopup inplaceIntroduceFieldPopup) {
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
inplaceIntroduceFieldPopup.setReplaceAllOccurrences(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void doTest(final Pass<InplaceIntroduceParameterPopup> pass) throws Exception {
|
||||
String name = getTestName(true);
|
||||
configureByFile(BASE_PATH + name + ".java");
|
||||
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
|
||||
TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(getProject());
|
||||
try {
|
||||
templateManager.setTemplateTesting(true);
|
||||
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
|
||||
|
||||
final MyIntroduceParameterHandler introduceParameterHandler = new MyIntroduceParameterHandler();
|
||||
final PsiExpression expression =
|
||||
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class);
|
||||
if (expression != null) {
|
||||
introduceParameterHandler.invokeImpl(getProject(), expression, getEditor());
|
||||
} else {
|
||||
final PsiLocalVariable localVariable =
|
||||
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
|
||||
assertNotNull(localVariable);
|
||||
introduceParameterHandler.invokeImpl(getProject(), localVariable, getEditor());
|
||||
}
|
||||
pass.pass(introduceParameterHandler.getInplaceIntroduceParameterPopup());
|
||||
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
|
||||
assert state != null;
|
||||
state.gotoEnd(false);
|
||||
checkResultByFile(BASE_PATH + name + "_after.java");
|
||||
}
|
||||
finally {
|
||||
myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
|
||||
templateManager.setTemplateTesting(false);
|
||||
}
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return BASE_PATH;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected MyIntroduceHandler createIntroduceHandler() {
|
||||
return new MyIntroduceParameterHandler();
|
||||
}
|
||||
|
||||
public void testEscapePosition() throws Exception {
|
||||
doTestEscape();
|
||||
@@ -88,39 +65,8 @@ public class InplaceIntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
doTestEscape();
|
||||
}
|
||||
|
||||
private void doTestEscape() throws Exception {
|
||||
String name = getTestName(true);
|
||||
configureByFile(BASE_PATH + name + ".java");
|
||||
final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled();
|
||||
TemplateManagerImpl templateManager = (TemplateManagerImpl)TemplateManager.getInstance(getProject());
|
||||
try {
|
||||
templateManager.setTemplateTesting(true);
|
||||
getEditor().getSettings().setVariableInplaceRenameEnabled(true);
|
||||
|
||||
final MyIntroduceParameterHandler introduceParameterHandler = new MyIntroduceParameterHandler();
|
||||
final PsiExpression expression =
|
||||
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiExpression.class);
|
||||
if (expression != null) {
|
||||
introduceParameterHandler.invokeImpl(getProject(), expression, getEditor());
|
||||
} else {
|
||||
final PsiLocalVariable localVariable =
|
||||
PsiTreeUtil.getParentOfType(getFile().findElementAt(getEditor().getCaretModel().getOffset()), PsiLocalVariable.class);
|
||||
assertNotNull(localVariable);
|
||||
introduceParameterHandler.invokeImpl(getProject(), localVariable, getEditor());
|
||||
}
|
||||
TemplateState state = TemplateManagerImpl.getTemplateState(getEditor());
|
||||
assert state != null;
|
||||
state.gotoEnd(true);
|
||||
checkResultByFile(BASE_PATH + name + "_after.java");
|
||||
}
|
||||
finally {
|
||||
myEditor.getSettings().setVariableInplaceRenameEnabled(enabled);
|
||||
templateManager.setTemplateTesting(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static class MyIntroduceParameterHandler extends IntroduceParameterHandler {
|
||||
private static class MyIntroduceParameterHandler extends IntroduceParameterHandler implements MyIntroduceHandler {
|
||||
|
||||
@Override
|
||||
public boolean invokeImpl(Project project, @NotNull PsiExpression selectedExpr, Editor editor) {
|
||||
|
||||
Reference in New Issue
Block a user