[uast] less conversions for junit references

GitOrigin-RevId: b4b91ef5b2b2eb704e33b99de0879de03d30e467
This commit is contained in:
Anna Kozlova
2022-08-01 10:00:50 +02:00
committed by intellij-monorepo-bot
parent 8e0fcbf388
commit 14361cd201
2 changed files with 30 additions and 4 deletions

View File

@@ -109,7 +109,11 @@ final class JUnitReferenceContributor extends PsiReferenceContributor {
UElement element = type.getUastParent();
boolean parameterFound = false;
for (int i = 0; i < 5 && element != null; i++) {
if (element instanceof UFile) {
if (element instanceof UFile ||
element instanceof UDeclaration ||
element instanceof UDeclarationsExpression ||
element instanceof UJumpExpression ||
element instanceof UBlockExpression) {
return false;
}
if (element instanceof UNamedExpression) {
@@ -120,9 +124,6 @@ final class JUnitReferenceContributor extends PsiReferenceContributor {
}
parameterFound = true;
}
if (element instanceof UDeclarationsExpression) {
return false;
}
if (element instanceof UAnnotation) {
UAnnotation annotation = (UAnnotation)element;
return parameterFound && myAnnotation.equals(annotation.getQualifiedName());

View File

@@ -281,6 +281,31 @@ class KotlinJUnitMalformedDeclarationInspectionTest : JUnitMalformedDeclarationI
}
""".trimIndent())
}
fun `test method source in another class`() {
myFixture.addFileToProject("SampleTest.kt", """"
open class SampleTest {
companion object {
@kotlin.jvm.JvmStatic
fun squares() : List<org.junit.jupiter.params.provider.Arguments> {
return listOf(
org.junit.jupiter.params.provider.Arguments.of(1, 1)
)
}
}
}""".trimIndent())
myFixture.testHighlighting(ULanguage.JAVA, """
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
class MethodSourceUsage {
@ParameterizedTest
@MethodSource("SampleTest#squares")
void testSquares(int input, int expected) {}
}
""".trimIndent())
}
fun `test malformed parameterized value source multiple parameters`() {
myFixture.testHighlighting(ULanguage.KOTLIN, """
class ValueSourcesTest {