Skip to content

Commit

Permalink
Merge pull request #662 from daniel-pichl/fix-string-ioobe
Browse files Browse the repository at this point in the history
Fix StringIndexOutOfBoundsException in LintUtils
  • Loading branch information
yasanglass authored Nov 14, 2024
2 parents 135c186 + 9c41770 commit 32b4259
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 32b4259

Please sign in to comment.