mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-20 13:31:28 +07:00
IDEA-112555 Bad code is green with method references on instance
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -107,6 +107,15 @@ public class PsiMethodReferenceUtil {
|
||||
}
|
||||
return new QualifierResolveResult(containingClass, substitutor, false);
|
||||
}
|
||||
|
||||
public static boolean isStaticallyReferenced(@NotNull PsiMethodReferenceExpression methodReferenceExpression) {
|
||||
final PsiExpression qualifierExpression = methodReferenceExpression.getQualifierExpression();
|
||||
if (qualifierExpression != null) {
|
||||
return qualifierExpression instanceof PsiReferenceExpression &&
|
||||
((PsiReferenceExpression)qualifierExpression).resolve() instanceof PsiClass;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isAcceptable(@Nullable final PsiMethodReferenceExpression methodReferenceExpression, PsiType left) {
|
||||
if (methodReferenceExpression == null) return false;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -427,7 +427,9 @@ public class PsiMethodReferenceExpressionImpl extends PsiReferenceExpressionBase
|
||||
|
||||
boolean hasReceiver = false;
|
||||
final PsiType[] parameterTypes = mySignature.getParameterTypes();
|
||||
if (parameterTypes.length > 0 && PsiMethodReferenceUtil.isReceiverType(parameterTypes[0], myContainingClass, mySubstitutor)) {
|
||||
if (parameterTypes.length > 0 &&
|
||||
PsiMethodReferenceUtil.isReceiverType(parameterTypes[0], myContainingClass, mySubstitutor) &&
|
||||
PsiMethodReferenceUtil.isStaticallyReferenced(PsiMethodReferenceExpressionImpl.this)) {
|
||||
hasReceiver = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
class ThreadExample {
|
||||
interface Function<T, R> {
|
||||
|
||||
R apply(T t);
|
||||
}
|
||||
{
|
||||
A a = new A();
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'ThreadExample.Function<? super ThreadExample.A,? extends java.lang.String>'">Function<? super A,? extends String> foo = a::foo;</error>
|
||||
}
|
||||
|
||||
static class A {
|
||||
public String foo() { return "a"; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testAbstractMethod() { doTest(); }
|
||||
public void testMethodRefAcceptance() { doTest(); }
|
||||
public void testVarargsMethodRef() { doTest(); }
|
||||
public void testExprReceiver() { doTest(); }
|
||||
|
||||
public void testTypeParameterWithExtendsList() throws Exception {
|
||||
doTest();
|
||||
|
||||
Reference in New Issue
Block a user