move instance method with method ref: ensure qualifier is not deleted

IDEA-181919
This commit is contained in:
Anna.Kozlova
2017-11-13 16:41:50 +01:00
parent df9fe45138
commit 5758bb4185
4 changed files with 36 additions and 2 deletions
@@ -500,8 +500,13 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
}
}
}
//Target is a field, replace target.m -> m
qualifier.delete();
if (expression instanceof PsiMethodReferenceExpression) {
qualifier.replace(factory.createExpressionFromText("this", null));
}
else {
//Target is a field, replace target.m -> m
qualifier.delete();
}
return;
}
if (myTargetVariable.equals(resolved)) {
@@ -0,0 +1,12 @@
import java.util.function.Consumer;
class Source {
public void f<caret>oo(Destination destination) {
Consumer<String> doSomething = destination::doSomething;
}
}
class Destination {
public void doSomething(String s) {
}
}
@@ -0,0 +1,13 @@
import java.util.function.Consumer;
class Source {
}
class Destination {
public void doSomething(String s) {
}
public void foo() {
Consumer<String> doSomething = this::doSomething;
}
}
@@ -116,6 +116,10 @@ public class MoveInstanceMethodTest extends LightRefactoringTestCase {
doTest(false, 0);
}
public void testMethodReferenceWithThisTarget() {
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest(true, 0));
}
public void testMethodReferenceToExpandToLambda() {
BaseRefactoringProcessor.ConflictsInTestsException.withIgnoredConflicts(() -> doTest(true, 1));
}