diff --git a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InheritanceUtil.java b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InheritanceUtil.java index 78576339cc31..9661ba10e4c4 100644 --- a/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InheritanceUtil.java +++ b/plugins/InspectionGadgets/InspectionGadgetsAnalysis/src/com/siyeh/ig/psiutils/InheritanceUtil.java @@ -23,8 +23,10 @@ import com.intellij.psi.PsiTypeParameter; import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.search.SearchScope; import com.intellij.psi.search.searches.ClassInheritorsSearch; +import com.intellij.psi.search.searches.FunctionalExpressionSearch; import com.intellij.util.Processor; import com.intellij.util.Query; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.atomic.AtomicInteger; @@ -75,8 +77,9 @@ public class InheritanceUtil { return result[0]; } - public static boolean hasImplementation(PsiClass aClass) { + public static boolean hasImplementation(@NotNull PsiClass aClass) { final SearchScope scope = GlobalSearchScope.projectScope(aClass.getProject()); + if (aClass.isInterface() && FunctionalExpressionSearch.search(aClass, scope).findFirst() != null) return true; final Query search = ClassInheritorsSearch.search(aClass, scope, true, true); return !search.forEach(new Processor() { @Override diff --git a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/interface_never_implemented/InterfaceNeverImplemented.java b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/interface_never_implemented/InterfaceNeverImplemented.java index 259a599e16c3..dc2cb71916bf 100644 --- a/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/interface_never_implemented/InterfaceNeverImplemented.java +++ b/plugins/InspectionGadgets/test/com/siyeh/igtest/inheritance/interface_never_implemented/InterfaceNeverImplemented.java @@ -5,4 +5,14 @@ interface InterfaceWithOnlyOneDirectInheritor {} class Inheritor implements InterfaceWithOnlyOneDirectInheritor {} interface InterfaceWithTwoInheritors {} class Inheritor1 implements InterfaceWithTwoInheritors {} -class Inheritor2 implements InterfaceWithTwoInheritors {} \ No newline at end of file +class Inheritor2 implements InterfaceWithTwoInheritors {} + +interface SAM { + void foo(); +} + +class LambdaCall { + { + SAM sam = () -> {}; + } +} \ No newline at end of file diff --git a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/InterfaceNeverImplementedInspectionTest.java b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/InterfaceNeverImplementedInspectionTest.java index 4453a28be228..d0bbbac1b820 100644 --- a/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/InterfaceNeverImplementedInspectionTest.java +++ b/plugins/InspectionGadgets/testsrc/com/siyeh/ig/inheritance/InterfaceNeverImplementedInspectionTest.java @@ -1,10 +1,29 @@ package com.siyeh.ig.inheritance; +import com.intellij.codeInspection.ex.LocalInspectionToolWrapper; +import com.intellij.openapi.projectRoots.Sdk; +import com.intellij.openapi.roots.LanguageLevelProjectExtension; +import com.intellij.pom.java.LanguageLevel; +import com.intellij.testFramework.IdeaTestUtil; import com.siyeh.ig.IGInspectionTestCase; public class InterfaceNeverImplementedInspectionTest extends IGInspectionTestCase { public void test() throws Exception { - doTest("com/siyeh/igtest/inheritance/interface_never_implemented", new InterfaceNeverImplementedInspection()); + final LanguageLevelProjectExtension levelProjectExtension = LanguageLevelProjectExtension.getInstance(getProject()); + final LanguageLevel level = levelProjectExtension.getLanguageLevel(); + try { + levelProjectExtension.setLanguageLevel(LanguageLevel.JDK_1_8); + doTest("com/siyeh/igtest/inheritance/interface_never_implemented", + new LocalInspectionToolWrapper(new InterfaceNeverImplementedInspection()), "java 1.8"); + } + finally { + levelProjectExtension.setLanguageLevel(level); + } + } + + @Override + protected Sdk getTestProjectSdk() { + return IdeaTestUtil.getMockJdk18(); } }