Create FqName safely in KotlinCliJavaFileManagerImpl#findPackage
#KT-7501 Fixed
This commit is contained in:
+7
-3
@@ -78,7 +78,8 @@ public class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager)
|
|||||||
|
|
||||||
override fun findPackage(packageName: String): PsiPackage? {
|
override fun findPackage(packageName: String): PsiPackage? {
|
||||||
var found = false
|
var found = false
|
||||||
index.traverseDirectoriesInPackage(FqName(packageName)) { _, __ ->
|
val packageFqName = packageName.toSafeFqName() ?: return null
|
||||||
|
index.traverseDirectoriesInPackage(packageFqName) { _, __ ->
|
||||||
found = true
|
found = true
|
||||||
//abort on first found
|
//abort on first found
|
||||||
false
|
false
|
||||||
@@ -149,8 +150,8 @@ public class KotlinCliJavaFileManagerImpl(private val myPsiManager: PsiManager)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// a sad workaround to avoid throwing exception when called from inside IDEA code
|
// a sad workaround to avoid throwing exception when called from inside IDEA code
|
||||||
private fun String.toSafeTopLevelClassId(): ClassId? = try {
|
private fun <T : Any> safely(compute: () -> T): T? = try {
|
||||||
ClassId.topLevel(FqName(this))
|
compute()
|
||||||
}
|
}
|
||||||
catch (e: IllegalArgumentException) {
|
catch (e: IllegalArgumentException) {
|
||||||
null
|
null
|
||||||
@@ -158,3 +159,6 @@ catch (e: IllegalArgumentException) {
|
|||||||
catch (e: AssertionError) {
|
catch (e: AssertionError) {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun String.toSafeFqName(): FqName? = safely { FqName(this) }
|
||||||
|
private fun String.toSafeTopLevelClassId(): ClassId? = safely { ClassId.topLevel(FqName(this)) }
|
||||||
Reference in New Issue
Block a user