mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-118774 Warning about lack of subclasses when using lambdas
This commit is contained in:
+4
-1
@@ -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<PsiClass> search = ClassInheritorsSearch.search(aClass, scope, true, true);
|
||||
return !search.forEach(new Processor<PsiClass>() {
|
||||
@Override
|
||||
|
||||
+11
-1
@@ -5,4 +5,14 @@ interface InterfaceWithOnlyOneDirectInheritor {}
|
||||
class Inheritor implements InterfaceWithOnlyOneDirectInheritor {}
|
||||
interface InterfaceWithTwoInheritors {}
|
||||
class Inheritor1 implements InterfaceWithTwoInheritors {}
|
||||
class Inheritor2 implements InterfaceWithTwoInheritors {}
|
||||
class Inheritor2 implements InterfaceWithTwoInheritors {}
|
||||
|
||||
interface SAM {
|
||||
void foo();
|
||||
}
|
||||
|
||||
class LambdaCall {
|
||||
{
|
||||
SAM sam = () -> {};
|
||||
}
|
||||
}
|
||||
+20
-1
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user