create subclass: restore caret position after delegate constructors are inserted (IDEA-105566)

This commit is contained in:
anna
2013-04-17 15:58:51 +02:00
parent b18149e338
commit 47d6ba424e
6 changed files with 38 additions and 6 deletions
@@ -96,7 +96,7 @@ public class CreateConstructorMatchingSuperFix extends BaseIntentionAction {
LOG.assertTrue(constructors.length >=1); // Otherwise we won't have been messing with all this stuff
boolean isCopyJavadoc = true;
if (constructors.length > 1) {
if (constructors.length > 1 && !ApplicationManager.getApplication().isUnitTestMode()) {
MemberChooser<PsiMethodMember> chooser = new MemberChooser<PsiMethodMember>(constructors, false, true, project);
chooser.setTitle(QuickFixBundle.message("super.class.constructors.chooser.title"));
chooser.show();
@@ -245,7 +245,7 @@ public class CreateSubclassAction extends BaseIntentionAction {
}
if (psiClass.hasTypeParameters() || includeClassName) {
final Editor editor = CodeInsightUtil.positionCursor(project, targetClass.getContainingFile(), targetClass.getLBrace());
final TemplateBuilderImpl templateBuilder = editor != null && !ApplicationManager.getApplication().isUnitTestMode()
final TemplateBuilderImpl templateBuilder = editor != null
? (TemplateBuilderImpl)TemplateBuilderFactory.getInstance().createTemplateBuilder(targetClass) : null;
if (includeClassName && templateBuilder != null) {
@@ -319,9 +319,11 @@ public class CreateSubclassAction extends BaseIntentionAction {
baseConstructors.add(new PsiMethodMember(baseConstr, substitutor));
}
}
final int offset = editor.getCaretModel().getOffset();
CreateConstructorMatchingSuperFix.chooseConstructor2Delegate(project, editor,
substitutor,
baseConstructors, constructors, targetClass);
editor.getCaretModel().moveToOffset(offset);
}
OverrideImplementUtil.chooseAndImplementMethods(project, editor, targetClass);
@@ -1,6 +1,5 @@
public class Test {
private interface Inner {}
public class InnerImpl implements Inner {
}
public class InnerImpl implements Inner { }
}
@@ -0,0 +1,17 @@
public class Test {
private abstract class Inner {
Inner(String s){}
abstract void bar();
}
public class InnerImpl extends Inner {
InnerImpl(String s) {
super(s);
}
@Override
void bar() {
//To change body of implemented methods use File | Settings | File Templates.
}
}
}
@@ -0,0 +1,6 @@
public class Test {
private abstract class Inner {
Inner(String s){}
abstract void bar();
}
}
@@ -1,11 +1,11 @@
package com.intellij.codeInsight.intention;
import com.intellij.codeInsight.intention.impl.CreateSubclassAction;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.search.ProjectScope;
import com.intellij.refactoring.MultiFileTestCase;
import com.intellij.codeInsight.intention.impl.CreateSubclassAction;
/**
* @author yole
@@ -14,8 +14,16 @@ public class CreateSubclassTest extends MultiFileTestCase {
public void testGenerics() throws Exception {
doTest();
}
public void testInnerClassImplement() throws Exception {
doTestInner();
}
public void testInnerClass() throws Exception {
doTestInner();
}
private void doTestInner() throws Exception {
doTest(new PerformAction() {
@Override
public void performAction(final VirtualFile rootDir, final VirtualFile rootAfter) throws Exception {