diff --git a/ij/src/main/kotlin/org/jetbrains/academy/test/system/ij/analyzer/IjCodeAnalyzerUtil.kt b/ij/src/main/kotlin/org/jetbrains/academy/test/system/ij/analyzer/IjCodeAnalyzerUtil.kt index a4e8f52..a79ab0e 100644 --- a/ij/src/main/kotlin/org/jetbrains/academy/test/system/ij/analyzer/IjCodeAnalyzerUtil.kt +++ b/ij/src/main/kotlin/org/jetbrains/academy/test/system/ij/analyzer/IjCodeAnalyzerUtil.kt @@ -126,7 +126,7 @@ private fun getParentText(element: PsiElement, isParentTypeFunction: Boolean): S * If false, the parent element is expected to be a class or any other non-function type. * @return True if the PsiFile contains an expression with the given text and the specified parent, false otherwise. */ -fun PsiFile.hasExpressionWithParent(expression: String, parent: String, isParentTypeFunction: Boolean): Boolean = +fun PsiFile.hasExpressionWithParent(expression: String, parent: String?, isParentTypeFunction: Boolean): Boolean = ApplicationManager.getApplication().runReadAction { val expressions: MutableCollection = extractElementsOfTypes(KtDotQualifiedExpression::class.java, KtCallExpression::class.java) diff --git a/ij/src/main/kotlin/org/jetbrains/academy/test/system/test/BaseIjTestClass.kt b/ij/src/main/kotlin/org/jetbrains/academy/test/system/test/BaseIjTestClass.kt index edaaeef..7c97a67 100644 --- a/ij/src/main/kotlin/org/jetbrains/academy/test/system/test/BaseIjTestClass.kt +++ b/ij/src/main/kotlin/org/jetbrains/academy/test/system/test/BaseIjTestClass.kt @@ -23,6 +23,6 @@ open class BaseIjTestClass : BasePlatformTestCase() { fun hasMethod(methodName: String): Boolean = myFixture.file.hasMethod(methodName) - fun hasExpressionWithParent(expression: String, parent: String, isParentTypeFunction: Boolean = false): Boolean = + fun hasExpressionWithParent(expression: String, parent: String?, isParentTypeFunction: Boolean = false): Boolean = myFixture.file.hasExpressionWithParent(expression, parent, isParentTypeFunction) } diff --git a/ij/src/test/kotlin/org/jetbrains/academy/test/system/ij/formatting/BaseIjTestClassTests.kt b/ij/src/test/kotlin/org/jetbrains/academy/test/system/ij/formatting/BaseIjTestClassTests.kt index 6205d30..b1c924a 100644 --- a/ij/src/test/kotlin/org/jetbrains/academy/test/system/ij/formatting/BaseIjTestClassTests.kt +++ b/ij/src/test/kotlin/org/jetbrains/academy/test/system/ij/formatting/BaseIjTestClassTests.kt @@ -194,8 +194,8 @@ class BaseIjTestClassTests : BaseIjTestClass() { } """.trimIndent() myFixture.configureByText("Task.kt", example) - var expression = "productPrice.sum()" - var parent = "productPrice.sum() / productPrice.count()" + var expression: String = "productPrice.sum()" + var parent: String? = "productPrice.sum() / productPrice.count()" assert(hasExpressionWithParent(expression, parent)) { "There must exist an expression $expression with parent $parent" } @@ -212,5 +212,10 @@ class BaseIjTestClassTests : BaseIjTestClass() { expression = "Int.MAX_VALUE" parent = "val CONSTANT = Int.MAX_VALUE" assertFalse(hasExpressionWithParent(expression, parent)) + expression = "Int.MAX_VALUE" + parent = null + assert(hasExpressionWithParent(expression, parent, true)) { + "There must exist an expression $expression with parent $parent" + } } }