mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-19 04:51:24 +07:00
method refs: check if interface functional (IDEA-125511)
This commit is contained in:
@@ -1234,11 +1234,19 @@ public class HighlightVisitorImpl extends JavaElementVisitor implements Highligh
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
final PsiType functionalInterfaceType = expression.getFunctionalInterfaceType();
|
||||
if (functionalInterfaceType != null && LambdaUtil.dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression)) {
|
||||
HighlightInfo result1 =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Cyclic inference").create();
|
||||
myHolder.add(result1); //todo[ann] append not inferred type params info
|
||||
} else {
|
||||
if (functionalInterfaceType != null) {
|
||||
final boolean notFunctional = !LambdaUtil.isFunctionalType(functionalInterfaceType);
|
||||
if (notFunctional) {
|
||||
myHolder.add(HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression)
|
||||
.descriptionAndTooltip(functionalInterfaceType.getPresentableText() + " is not a functional interface").create());
|
||||
}
|
||||
else if (LambdaUtil.dependsOnTypeParams(functionalInterfaceType, functionalInterfaceType, expression)) {
|
||||
HighlightInfo result1 =
|
||||
HighlightInfo.newHighlightInfo(HighlightInfoType.ERROR).range(expression).descriptionAndTooltip("Cyclic inference").create();
|
||||
myHolder.add(result1); //todo[ann] append not inferred type params info
|
||||
}
|
||||
}
|
||||
if (!myHolder.hasErrorResults()) {
|
||||
final PsiElement referenceNameElement = expression.getReferenceNameElement();
|
||||
if (referenceNameElement instanceof PsiKeyword) {
|
||||
if (!PsiMethodReferenceUtil.isValidQualifier(expression)) {
|
||||
|
||||
@@ -38,5 +38,5 @@ class Test2 {
|
||||
|
||||
void foo(Integer i) {}
|
||||
|
||||
<error descr="Incompatible types. Found: '<method reference>', required: 'java.lang.Object'">Object o = Test2::foo;</error>
|
||||
Object o = <error descr="Object is not a functional interface">Test2::foo</error>;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
class Java8 {
|
||||
public void test() {
|
||||
}
|
||||
|
||||
private int m() {
|
||||
return <error descr="int is not a functional interface">Java8::test</error>;
|
||||
}
|
||||
}
|
||||
@@ -102,6 +102,9 @@ public class MethodRefHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testQualifiersInStaticContext() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
public void testInvalidFunctionalTypeInReturnStmt() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doTest(false);
|
||||
|
||||
Reference in New Issue
Block a user