inline: don't check containing method call if inline to method reference

This commit is contained in:
Anna.Kozlova
2017-03-14 14:17:14 +01:00
parent 1e9f6352f2
commit 9574fa7a6e
4 changed files with 29 additions and 1 deletions
@@ -27,7 +27,6 @@ import com.intellij.psi.search.LocalSearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiTypesUtil;
import com.intellij.psi.util.RedundantCastUtil;
import com.intellij.refactoring.RefactoringBundle;
import com.intellij.util.IncorrectOperationException;
@@ -297,6 +296,7 @@ public class InlineUtil {
public static TailCallType getTailCallType(@NotNull final PsiReference psiReference) {
PsiElement element = psiReference.getElement();
if (element instanceof PsiMethodReferenceExpression) return TailCallType.None;
PsiExpression methodCall = PsiTreeUtil.getParentOfType(element, PsiMethodCallExpression.class);
if (methodCall == null) return TailCallType.None;
if (methodCall.getParent() instanceof PsiReturnStatement) return TailCallType.Return;
@@ -0,0 +1,14 @@
import java.util.function.Supplier;
class Foo {
static int m() {
return 1;
}
void o(){
mm(Foo::<caret>m);
}
void mm(Supplier<Integer> r) {}
}
@@ -0,0 +1,10 @@
import java.util.function.Supplier;
class Foo {
void o(){
mm(() -> 1);
}
void mm(Supplier<Integer> r) {}
}
@@ -231,6 +231,10 @@ public class InlineMethodTest extends LightRefactoringTestCase {
doTestConflict("Inline cannot be applied to multiline method in constructor call");
}
public void testMethodReferenceInsideMethodCall() throws Exception {
doTest();
}
private void doTestConflict(final String conflict) throws Exception {
try {
doTest();