method ref: introduce method ref variable; accept method ref type separately

This commit is contained in:
anna
2012-09-25 19:47:03 +02:00
parent 97b9fbee9a
commit 71eb8ec93e
6 changed files with 44 additions and 1 deletions
@@ -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>"));
}