mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
introduce variable: suggest method reference expression (IDEA-102852)
This commit is contained in:
+4
-3
@@ -197,9 +197,10 @@ public abstract class IntroduceVariableBase extends IntroduceHandlerBase {
|
||||
PsiExpression expression = PsiTreeUtil.getParentOfType(elementAtCaret, PsiExpression.class);
|
||||
while (expression != null) {
|
||||
if (!expressions.contains(expression) && !(expression instanceof PsiParenthesizedExpression) && !(expression instanceof PsiSuperExpression) && expression.getType() != PsiType.VOID) {
|
||||
if (!(expression instanceof PsiReferenceExpression && (expression.getParent() instanceof PsiMethodCallExpression ||
|
||||
((PsiReferenceExpression)expression).resolve() instanceof PsiClass))
|
||||
&& !(expression instanceof PsiAssignmentExpression)) {
|
||||
if (expression instanceof PsiMethodReferenceExpression ||
|
||||
!(expression instanceof PsiReferenceExpression &&
|
||||
(expression.getParent() instanceof PsiMethodCallExpression || ((PsiReferenceExpression)expression).resolve() instanceof PsiClass)) &&
|
||||
!(expression instanceof PsiAssignmentExpression)) {
|
||||
expressions.add(expression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
class Foo {
|
||||
interface I {
|
||||
Integer[] _(int p);
|
||||
}
|
||||
void test() {
|
||||
I m = Integer[]::new;
|
||||
I i = m;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Foo {
|
||||
interface I {
|
||||
Integer[] _(int p);
|
||||
}
|
||||
void test() {
|
||||
I i = Integer[]:<caret>:new;
|
||||
}
|
||||
}
|
||||
@@ -392,6 +392,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("i3", false, false, false, "int"));
|
||||
}
|
||||
|
||||
public void testMethodReferenceExpr() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("m", false, false, false, "Foo.I"));
|
||||
}
|
||||
|
||||
private void doTest(IntroduceVariableBase testMe) throws Exception {
|
||||
@NonNls String baseName = "/refactoring/introduceVariable/" + getTestName(false);
|
||||
configureByFile(baseName + ".java");
|
||||
|
||||
Reference in New Issue
Block a user