mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
unused declaration: add refs on functional interface from functional expressions (IDEA-132138)
This commit is contained in:
+23
@@ -92,6 +92,29 @@ public class RefJavaUtilImpl extends RefJavaUtil{
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitLambdaExpression(PsiLambdaExpression expression) {
|
||||
super.visitLambdaExpression(expression);
|
||||
processFunctionalExpression(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitMethodReferenceExpression(PsiMethodReferenceExpression expression) {
|
||||
super.visitMethodReferenceExpression(expression);
|
||||
processFunctionalExpression(expression);
|
||||
}
|
||||
|
||||
private void processFunctionalExpression(PsiFunctionalExpression expression) {
|
||||
final PsiClass aClass = PsiUtil.resolveClassInType(expression.getFunctionalInterfaceType());
|
||||
if (aClass != null) {
|
||||
refFrom.addReference(refFrom.getRefManager().getReference(aClass), aClass, psiFrom, false, true, null);
|
||||
final PsiMethod interfaceMethod = LambdaUtil.getFunctionalInterfaceMethod(aClass);
|
||||
if (interfaceMethod != null) {
|
||||
refFrom.addReference(refFrom.getRefManager().getReference(interfaceMethod), interfaceMethod, psiFrom, false, true, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private RefMethod processNewLikeConstruct(final PsiMethod psiConstructor, final PsiExpressionList argumentList) {
|
||||
if (psiConstructor != null) {
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<problems/>
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
public class Test {
|
||||
public static void main(String[] args) {
|
||||
final Memento m = () -> isPlaying;
|
||||
System.out.println(m);
|
||||
}
|
||||
|
||||
public static interface Memento {
|
||||
boolean isPlaying();
|
||||
}
|
||||
}
|
||||
@@ -190,4 +190,9 @@ public class UnusedDeclarationTest extends InspectionTestCase {
|
||||
public void testClassLiteralRef() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFunctionalExpressions() {
|
||||
LanguageLevelProjectExtension.getInstance(getJavaFacade().getProject()).setLanguageLevel(LanguageLevel.JDK_1_8);
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user