AA: fail-safe JvmRoot lookup
This commit is contained in:
committed by
Ilya Kirillov
parent
aef3df0336
commit
af053fd8f3
+12
-9
@@ -118,16 +118,19 @@ object StandaloneProjectFactory {
|
|||||||
val result = mutableSetOf<PsiDirectory>()
|
val result = mutableSetOf<PsiDirectory>()
|
||||||
for (file in files) {
|
for (file in files) {
|
||||||
val packageParts = file.packageName.takeIf { it.isNotEmpty() }?.split('.') ?: emptyList()
|
val packageParts = file.packageName.takeIf { it.isNotEmpty() }?.split('.') ?: emptyList()
|
||||||
val javaDir = packageParts
|
var javaDir: PsiDirectory? = file.parent
|
||||||
.reversed()
|
for (part in packageParts.reversed()) {
|
||||||
.fold(file.parent) { dir, part ->
|
if (javaDir?.name == part) {
|
||||||
if (dir?.name == part) {
|
javaDir = javaDir.parent
|
||||||
dir.parent
|
} else {
|
||||||
} else {
|
// Error(ish): file package does not match file path.
|
||||||
error("File package ${file.packageName} does not match file path ${file.virtualFile.path}")
|
// This could happen if, e.g., src/my/pkg/MyTest.java has package `test.pkg`.
|
||||||
}
|
// It is just best practice, not enforced by language spec.
|
||||||
|
// So, here, we just stop iterating upward the folder structure.
|
||||||
|
break
|
||||||
}
|
}
|
||||||
result += javaDir as PsiDirectory
|
}
|
||||||
|
javaDir?.let { result += it }
|
||||||
}
|
}
|
||||||
return result.toList()
|
return result.toList()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user