[LL API] Check the class file is in a conventional place
Although 'VirtualFile's are typically inside the containing package directory, e.g. 'foo/bar/Baz.class' for 'foo.bar.Baz', there might be classes with files in unexpected places. Sources of such classes may include broken stubs, or just classes from misbehaving IDE plugins. As we are yet to identity such cases, here we treat them as 'other' candidates.
This commit is contained in:
+24
-2
@@ -96,7 +96,29 @@ private class LLLibraryScopeAwareConeCallConflictResolver(
|
||||
}
|
||||
|
||||
private fun getSymbolRootFile(virtualFile: VirtualFile, packageFqName: FqName): VirtualFile? {
|
||||
val nestingLevel = packageFqName.pathSegments().size
|
||||
return generateSequence(virtualFile) { it.parent }.drop(nestingLevel + 1).firstOrNull()
|
||||
val packageFqNameSegments = packageFqName.pathSegments().asReversed()
|
||||
val nestingLevel = packageFqNameSegments.size
|
||||
|
||||
var current = virtualFile
|
||||
var index = 0
|
||||
|
||||
while (true) {
|
||||
assert(index <= nestingLevel)
|
||||
|
||||
val parent = current.parent ?: return null
|
||||
|
||||
if (index == nestingLevel) {
|
||||
// Parent containing the root package is a class file root
|
||||
return parent
|
||||
}
|
||||
|
||||
if (parent.name != packageFqNameSegments[index].asString()) {
|
||||
// Unexpected directory structure, the class is in a non-conventional root
|
||||
return null
|
||||
}
|
||||
|
||||
current = parent
|
||||
index += 1
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user