Skip to content

Commit

Permalink
Fix StringIndexOutOfBoundsException in LintUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-pichl committed Nov 5, 2024
1 parent 135c186 commit 9c41770
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 9c41770

Please sign in to comment.