Java: Ignore bare method expression (without parentheses) when matching potential parameters of extracted method (IDEA-194264)

This commit is contained in:
Pavel Dolgov
2018-12-14 17:59:33 +03:00
parent 5429f0d839
commit 6923397466
5 changed files with 35 additions and 1 deletions
@@ -126,6 +126,8 @@ public final class Match {
final List<PsiElement> currentValue = myParameterValues.get(psiVariable);
final boolean isVararg = psiVariable instanceof PsiParameter && ((PsiParameter)psiVariable).isVarArgs();
if (!(value instanceof PsiExpression)) return false;
final PsiElement parent = value.getParent();
if (parent instanceof PsiMethodCallExpression && value == ((PsiMethodCallExpression)parent).getMethodExpression()) return false;
final PsiType type = ((PsiExpression)value).getType();
final PsiType parameterType = parameter.getType();
if (type == null) return false;
@@ -0,0 +1,12 @@
import java.util.List;
class C {
void m(List<String> list) {
int i = 0;
System.out.println(<selection>i</selection>);
if (list.size() > 0) {
System.out.println(list.size());
}
}
}
@@ -0,0 +1,16 @@
import java.util.List;
class C {
void m(List<String> list) {
int i = 0;
System.out.println(newMethod(i));
if (list.size() > 0) {
System.out.println(list.size());
}
}
private int newMethod(int i) {
return i;
}
}
@@ -1,7 +1,7 @@
class Test {
void t(java.util.Map<String, String> m) {
String f = "";
System.out.println("f = " + newMethod(f) + ", " + newMethod(newMethod(f)));
System.out.println("f = " + newMethod(f) + ", " + m.get(newMethod(f)));
}
private String newMethod(String f) {
@@ -1321,6 +1321,10 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
doDuplicatesTest();
}
public void testOneVariableExpression() throws Exception {
doDuplicatesTest();
}
public void testInterfaceMethodVisibility() throws Exception {
final String doesNotExist = "foo.bar.baz.DoesNotExist";
final NullableNotNullManager nullManager = NullableNotNullManager.getInstance(getProject());