mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
method ref: introduce method ref variable; accept method ref type separately
This commit is contained in:
@@ -28,4 +28,7 @@ public interface PsiMethodReferenceExpression extends PsiReferenceExpression {
|
||||
*/
|
||||
@Nullable
|
||||
PsiTypeElement getQualifierType();
|
||||
|
||||
@Nullable
|
||||
PsiType getFunctionalInterfaceType();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class PsiMethodReferenceType extends PsiType {
|
||||
|
||||
@Override
|
||||
public <A> A accept(@NotNull final PsiTypeVisitor<A> visitor) {
|
||||
return visitor.visitType(this);
|
||||
return visitor.visitMethodReferenceType(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -75,4 +75,11 @@ public class PsiTypeVisitor<A> {
|
||||
if (interfaceType != null) return interfaceType.accept(this);
|
||||
return visitType(interfaceType);
|
||||
}
|
||||
|
||||
public A visitMethodReferenceType(PsiMethodReferenceType methodReferenceType) {
|
||||
final PsiMethodReferenceExpression expression = methodReferenceType.getExpression();
|
||||
final PsiType interfaceType = expression.getFunctionalInterfaceType();
|
||||
if (interfaceType != null) return interfaceType.accept(this);
|
||||
return visitType(methodReferenceType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class Test {
|
||||
{
|
||||
Bar c = Test::length;
|
||||
bar(c);
|
||||
}
|
||||
|
||||
public static Integer length(String s) {
|
||||
return s.length();
|
||||
}
|
||||
|
||||
static void bar(Bar bar) {}
|
||||
interface Bar {
|
||||
Integer _(String s);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
class Test {
|
||||
{
|
||||
bar(<selection>Test::length</selection>);
|
||||
}
|
||||
|
||||
public static Integer length(String s) {
|
||||
return s.length();
|
||||
}
|
||||
|
||||
static void bar(Bar bar) {}
|
||||
interface Bar {
|
||||
Integer _(String s);
|
||||
}
|
||||
}
|
||||
@@ -373,6 +373,10 @@ public class IntroduceVariableTest extends LightCodeInsightTestCase {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, "SAM<java.lang.Integer>"));
|
||||
}
|
||||
|
||||
public void testMethodRef() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, "Test.Bar"));
|
||||
}
|
||||
|
||||
public void testLambdaExprNotAccepted() throws Exception {
|
||||
doTest(new MockIntroduceVariableHandler("c", false, false, false, "SAM<java.lang.String>"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user