diff --git a/java/openapi/src/com/intellij/codeInsight/MetaAnnotationUtil.java b/java/openapi/src/com/intellij/codeInsight/MetaAnnotationUtil.java index ca34d90be480..b17539067ada 100644 --- a/java/openapi/src/com/intellij/codeInsight/MetaAnnotationUtil.java +++ b/java/openapi/src/com/intellij/codeInsight/MetaAnnotationUtil.java @@ -5,7 +5,6 @@ import com.intellij.lang.Language; import com.intellij.lang.java.JavaLanguage; import com.intellij.openapi.module.Module; import com.intellij.openapi.progress.ProgressManager; -import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Pair; @@ -284,6 +283,24 @@ public abstract class MetaAnnotationUtil { return false; } + public static Stream findMetaAnnotationsInHierarchy( + @NotNull PsiModifierListOwner listOwner, + @NotNull Collection annotations + ) { + Stream stream = findMetaAnnotations(listOwner, annotations); + if (listOwner instanceof PsiClass) { + for (PsiClass superClass : ((PsiClass)listOwner).getSupers()) { + stream = Stream.concat(stream, findMetaAnnotations(superClass, annotations)); + } + } + else if (listOwner instanceof PsiMethod) { + for (PsiMethod method : ((PsiMethod)listOwner).findSuperMethods()) { + stream = Stream.concat(stream, findMetaAnnotations(method, annotations)); + } + } + return stream; + } + @Nullable private static PsiAnnotation metaAnnotationCached(PsiClass subjectAnnotation, String annotationToFind) { return CachedValuesManager.getCachedValue(subjectAnnotation, () -> { diff --git a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/test/junit/JUnitMalformedDeclarationInspection.kt b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/test/junit/JUnitMalformedDeclarationInspection.kt index 53eaaef95e55..34047bfe3308 100644 --- a/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/test/junit/JUnitMalformedDeclarationInspection.kt +++ b/jvm/jvm-analysis-impl/src/com/intellij/codeInspection/test/junit/JUnitMalformedDeclarationInspection.kt @@ -37,7 +37,6 @@ import org.jetbrains.uast.* import org.jetbrains.uast.visitor.AbstractUastNonRecursiveVisitor import javax.swing.JComponent import kotlin.streams.asSequence -import kotlin.streams.toList class JUnitMalformedDeclarationInspection : AbstractBaseUastLocalInspectionTool() { @JvmField @@ -204,7 +203,7 @@ private class JUnitMalformedSignatureVisitor( val sourcePsi = this.sourcePsi ?: return false val alternatives = UastFacade.convertToAlternatives(sourcePsi, arrayOf(UMethod::class.java)) val extension = alternatives.mapNotNull { it.javaPsi.containingClass }.flatMap { - MetaAnnotationUtil.findMetaAnnotations(it, listOf(ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH)).asSequence() + MetaAnnotationUtil.findMetaAnnotationsInHierarchy(it, listOf(ORG_JUNIT_JUPITER_API_EXTENSION_EXTEND_WITH)).asSequence() }.firstOrNull()?.findAttributeValue("value")?.toUElement() ?: return false if (extension is UClassLiteralExpression) return InheritanceUtil.isInheritor(extension.type, ORG_JUNIT_JUPITER_API_EXTENSION_PARAMETER_RESOLVER) diff --git a/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/codeInspection/tests/kotlin/test/junit/KotlinJUnitMalformedDeclarationInspectionTest.kt b/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/codeInspection/tests/kotlin/test/junit/KotlinJUnitMalformedDeclarationInspectionTest.kt index a8605ccfdc06..b54f9116539f 100644 --- a/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/codeInspection/tests/kotlin/test/junit/KotlinJUnitMalformedDeclarationInspectionTest.kt +++ b/jvm/jvm-analysis-kotlin-tests/testSrc/com/intellij/codeInspection/tests/kotlin/test/junit/KotlinJUnitMalformedDeclarationInspectionTest.kt @@ -663,7 +663,15 @@ class KotlinJUnitMalformedDeclarationInspectionTest : JUnitMalformedDeclarationI @org.junit.jupiter.api.BeforeAll fun beforeAll(foo: String) { println(foo) } } - } + } + + @org.junit.jupiter.api.extension.ExtendWith(TestParameterResolver::class) + open class AbstractTest { } + + class TestImplementation: AbstractTest() { + @org.junit.jupiter.api.BeforeEach + fun beforeEach(valueBox : String){ } + } @org.junit.jupiter.api.extension.ExtendWith(TestParameterResolver::class) annotation class CustomTestAnnotation @@ -675,7 +683,7 @@ class KotlinJUnitMalformedDeclarationInspectionTest : JUnitMalformedDeclarationI @org.junit.jupiter.api.BeforeAll fun beforeAll(foo: String) { println(foo) } } - } + } """.trimIndent()) } fun `test malformed before class method that is non-static`() {