move instance method when ref was inside anonymous inheritor (EA-87325 - IOE: PsiJavaParserFacadeImpl.createExpressionFromText)

This commit is contained in:
Anna Kozlova
2016-08-26 21:01:25 +03:00
parent 61fc2a8ec1
commit b3dcbeb29a
5 changed files with 54 additions and 2 deletions
@@ -26,6 +26,7 @@ import com.intellij.refactoring.move.MoveInstanceMembersUtil;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TitledSeparator;
import com.intellij.util.ObjectUtils;
import com.intellij.util.containers.HashMap;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.UIUtil;
@@ -123,7 +124,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
if (myThisClassesMap.size() == 0) return null;
JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
for (PsiClass aClass : myThisClassesMap.keySet()) {
final String text = RefactoringBundle.message("move.method.this.parameter.label", aClass.getName());
final String text = RefactoringBundle.message("move.method.this.parameter.label", ObjectUtils.notNull(aClass.getName(), ""));
panel.add(new TitledSeparator(text, null));
String suggestedName = MoveInstanceMethodHandler.suggestParameterNameForThisClass(aClass);
@@ -333,7 +333,13 @@ public class MoveInstanceMethodProcessor extends BaseRefactoringProcessor{
}
}
else {
thisArgumentText = classReferencedByThis.getName() + ".this";
final String name = classReferencedByThis.getName();
if (name != null) {
thisArgumentText = name + ".this";
}
else {
thisArgumentText = "this";
}
}
if (thisArgumentText != null) {
@@ -0,0 +1,20 @@
class A<T> {
class B {
private String foo;
public void run() {
new B() {
@Override
public void run() {
moo(A.this);
}
};
}
void m<caret>oo(A a) {
System.out.println(foo);
}
}
}
@@ -0,0 +1,21 @@
class A<T> {
void moo(B b) {
System.out.println(b.foo);
}
class B {
private String foo;
public void run() {
new B() {
@Override
public void run() {
A.this.moo(this);
}
};
}
}
}
@@ -85,6 +85,10 @@ public class MoveInstanceMethodTest extends LightRefactoringTestCase {
doTest(false, 0);
}
public void testUsageInAnonymousClass() throws Exception {
doTest(true, 0);
}
public void testMethodReference() throws Exception {
try {
doTest(true, 0);