mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-235734 false positive warning: inspection should check whether an element is PsiClass descendant
GitOrigin-RevId: 509445bd4a02c13d007b9c0cf37f559b2ec461bf
This commit is contained in:
committed by
intellij-monorepo-bot
parent
c5e88846c1
commit
82c7b69cd3
+6
-7
@@ -112,8 +112,8 @@ public class TestOnlyInspection extends AbstractBaseJavaLocalInspectionTool {
|
||||
if (vft == null && !isAnnotatedAsTestOnly(member)) {
|
||||
return true;
|
||||
}
|
||||
if (isInsideTestOnlyMethod(place) || isInsideTestOnlyField(place) || isInsideTestClass(place) || isUnderTestSources(place)
|
||||
|| isGenericType(place, member)) {
|
||||
if (isInsideTestOnlyMethod(place) || isInsideTestOnlyField(place) || isInsideTestOnlyClass(place) || isInsideTestClass(place)
|
||||
|| isUnderTestSources(place)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -174,6 +174,10 @@ public class TestOnlyInspection extends AbstractBaseJavaLocalInspectionTool {
|
||||
return isAnnotatedAsTestOnly(getTopLevelParentOfType(e, PsiField.class));
|
||||
}
|
||||
|
||||
private static boolean isInsideTestOnlyClass(@NotNull PsiElement e) {
|
||||
return isAnnotatedAsTestOnly(getTopLevelParentOfType(e, PsiClass.class));
|
||||
}
|
||||
|
||||
private static boolean isAnnotatedAsTestOnly(@Nullable PsiMember m) {
|
||||
if (m == null) return false;
|
||||
return isDirectlyTestOnly(m) || isAnnotatedAsTestOnly(m.getContainingClass());
|
||||
@@ -188,11 +192,6 @@ public class TestOnlyInspection extends AbstractBaseJavaLocalInspectionTool {
|
||||
return c != null && TestFrameworks.getInstance().isTestClass(c);
|
||||
}
|
||||
|
||||
private static boolean isGenericType(@NotNull PsiElement place, @NotNull PsiMember member) {
|
||||
PsiClass parent = PsiTreeUtil.getParentOfType(place, PsiClass.class);
|
||||
return member.equals(parent);
|
||||
}
|
||||
|
||||
private static <T extends PsiElement> T getTopLevelParentOfType(PsiElement e, Class<T> c) {
|
||||
T parent = PsiTreeUtil.getParentOfType(e, c);
|
||||
if (parent == null) return null;
|
||||
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
import java.util.List;
|
||||
|
||||
@TestOnly
|
||||
public class Bar {
|
||||
static abstract class Foo implements List<Bar> {
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
@TestOnly
|
||||
public class Bar {
|
||||
static {
|
||||
java.lang.Class<Bar> clazz = Bar.class;
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -80,7 +80,7 @@ public class TestOnlyInspectionTest extends JavaInspectionTestCase {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testGenericType() {
|
||||
public void testInsideTestOnlyClass() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user