mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-01-06 11:50:54 +07:00
introduce parameter, delegate: process supermethod accordingly (IDEA-57162)
This commit is contained in:
@@ -382,7 +382,16 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
}
|
||||
|
||||
if (myGenerateDelegate) {
|
||||
generateDelegate();
|
||||
generateDelegate(myMethodToReplaceIn);
|
||||
if (myMethodToReplaceIn != myMethodToSearchFor) {
|
||||
final PsiMethod method = generateDelegate(myMethodToSearchFor);
|
||||
if (method.getContainingClass().isInterface()) {
|
||||
final PsiCodeBlock block = method.getBody();
|
||||
if (block != null) {
|
||||
block.delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Changing signature of initial method
|
||||
@@ -428,16 +437,16 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
}
|
||||
}
|
||||
|
||||
private void generateDelegate() throws IncorrectOperationException {
|
||||
final PsiMethod delegate = (PsiMethod)myMethodToReplaceIn.copy();
|
||||
private PsiMethod generateDelegate(final PsiMethod methodToReplaceIn) throws IncorrectOperationException {
|
||||
final PsiMethod delegate = (PsiMethod)methodToReplaceIn.copy();
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(myManager.getProject()).getElementFactory();
|
||||
ChangeSignatureProcessor.makeEmptyBody(elementFactory, delegate);
|
||||
final PsiCallExpression callExpression = ChangeSignatureProcessor.addDelegatingCallTemplate(delegate, delegate.getName());
|
||||
final PsiExpressionList argumentList = callExpression.getArgumentList();
|
||||
assert argumentList != null;
|
||||
final PsiParameter[] psiParameters = myMethodToReplaceIn.getParameterList().getParameters();
|
||||
final PsiParameter[] psiParameters = methodToReplaceIn.getParameterList().getParameters();
|
||||
|
||||
final PsiParameter anchorParameter = getAnchorParameter(myMethodToReplaceIn);
|
||||
final PsiParameter anchorParameter = getAnchorParameter(methodToReplaceIn);
|
||||
if (psiParameters.length == 0) {
|
||||
argumentList.add(myParameterInitializer);
|
||||
}
|
||||
@@ -454,7 +463,7 @@ public class IntroduceParameterProcessor extends BaseRefactoringProcessor implem
|
||||
}
|
||||
}
|
||||
|
||||
myMethodToReplaceIn.getContainingClass().addBefore(delegate, myMethodToReplaceIn);
|
||||
return (PsiMethod)methodToReplaceIn.getContainingClass().addBefore(delegate, methodToReplaceIn);
|
||||
}
|
||||
|
||||
private void addDefaultConstructor(UsageInfo usage, UsageInfo[] usages) throws IncorrectOperationException {
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
abstract class A {
|
||||
void xxx() {
|
||||
xxx(239);
|
||||
}
|
||||
|
||||
abstract void xxx(final int anObject);
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
public void xxx() {
|
||||
xxx(239);
|
||||
}
|
||||
|
||||
public void xxx(final int anObject) {
|
||||
System.out.println(anObject);
|
||||
}
|
||||
|
||||
static {
|
||||
A a = new B();
|
||||
a.xxx();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
interface A {
|
||||
void xxx();
|
||||
|
||||
void xxx(final int anObject);
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
public void xxx() {
|
||||
xxx(239);
|
||||
}
|
||||
|
||||
public void xxx(final int anObject) {
|
||||
System.out.println(anObject);
|
||||
}
|
||||
|
||||
static {
|
||||
A a = new B();
|
||||
a.xxx();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
abstract class A {
|
||||
abstract void xxx();
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
public void xxx() {
|
||||
System.out.println(<selection>239</selection>);
|
||||
}
|
||||
|
||||
static {
|
||||
A a = new B();
|
||||
a.xxx();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
interface A {
|
||||
void xxx();
|
||||
}
|
||||
|
||||
class B implements A {
|
||||
public void xxx() {
|
||||
System.out.println(<selection>239</selection>);
|
||||
}
|
||||
|
||||
static {
|
||||
A a = new B();
|
||||
a.xxx();
|
||||
}
|
||||
}
|
||||
@@ -245,6 +245,14 @@ public class IntroduceParameterTest extends LightCodeInsightTestCase {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, false, true, false);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateInSuperClass() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, true, true, true);
|
||||
}
|
||||
|
||||
public void testGenerateDelegateInSuperInterface() throws Exception {
|
||||
doTest(IntroduceParameterRefactoring.REPLACE_FIELDS_WITH_GETTERS_ALL, true, true, true, true);
|
||||
}
|
||||
|
||||
private void doTestThroughHandler() throws Exception {
|
||||
configureByFile("/refactoring/introduceParameter/before" + getTestName(false) + ".java");
|
||||
new IntroduceParameterHandler().invoke(getProject(), myEditor, myFile, new DataContext() {
|
||||
|
||||
Reference in New Issue
Block a user