diff --git a/lint/src/main/kotlin/kiwi/orbit/compose/lint/detectors/LintUtils.kt b/lint/src/main/kotlin/kiwi/orbit/compose/lint/detectors/LintUtils.kt index e3e49a730..6d0d142a1 100644 --- a/lint/src/main/kotlin/kiwi/orbit/compose/lint/detectors/LintUtils.kt +++ b/lint/src/main/kotlin/kiwi/orbit/compose/lint/detectors/LintUtils.kt @@ -26,6 +26,7 @@ import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtSimpleNameExpression import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.isAncestor +import org.jetbrains.kotlin.utils.addToStdlib.lastIndexOfOrNull import org.jetbrains.uast.UCallExpression import org.jetbrains.uast.ULambdaExpression import org.jetbrains.uast.toUElement @@ -36,7 +37,11 @@ internal fun PsiMethod.isInPackageName(packageName: String): Boolean { } internal fun PsiElement.getPackageName(): String? = when (this) { - is PsiMember -> this.containingClass?.qualifiedName?.let { it.substring(0, it.lastIndexOf(".")) } + is PsiMember -> this.containingClass?.qualifiedName?.let { + it.lastIndexOfOrNull('.')?.let { endIndex -> + it.substring(0, endIndex) + } + } else -> null }