Improve search for facade light class by kotlin file
LightClassUtil#getWrappingClass works for clashing facade fq names #KT-17855 Fixed
This commit is contained in:
@@ -153,9 +153,7 @@ object LightClassUtil {
|
||||
|
||||
if (parent is KtFile) {
|
||||
// top-level declaration
|
||||
val fqName = parent.javaFileFacadeFqName
|
||||
val project = declaration.project
|
||||
return JavaElementFinder.getInstance(project).findClass(fqName.asString(), GlobalSearchScope.allScope(project))
|
||||
return findFileFacade(parent)
|
||||
}
|
||||
else if (parent is KtClassBody) {
|
||||
assert(parent.parent is KtClassOrObject)
|
||||
@@ -165,6 +163,17 @@ object LightClassUtil {
|
||||
return null
|
||||
}
|
||||
|
||||
private fun findFileFacade(ktFile: KtFile): PsiClass? {
|
||||
val fqName = ktFile.javaFileFacadeFqName
|
||||
val project = ktFile.project
|
||||
val classesWithMatchingFqName = JavaElementFinder.getInstance(project).findClasses(fqName.asString(), GlobalSearchScope.allScope(project))
|
||||
return classesWithMatchingFqName.singleOrNull() ?:
|
||||
classesWithMatchingFqName.find {
|
||||
// NOTE: for multipart facades this works via FakeLightClassForFileOfPackage
|
||||
it.containingFile?.virtualFile == ktFile.virtualFile
|
||||
}
|
||||
}
|
||||
|
||||
private fun getWrappingClasses(declaration: KtDeclaration): Sequence<PsiClass> {
|
||||
val wrapperClass = getWrappingClass(declaration) ?: return emptySequence()
|
||||
val wrapperClassOrigin = (wrapperClass as KtLightClass).kotlinOrigin
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
@file:JvmName("MultiPart")
|
||||
@file:JvmMultifileClass
|
||||
|
||||
package test.multiPart
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
@file:JvmName("MultiPart")
|
||||
@file:JvmMultifileClass
|
||||
|
||||
package test.multiPart
|
||||
|
||||
fun other() {
|
||||
|
||||
}
|
||||
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
package simple
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@file:JvmName("MultiPart")
|
||||
@file:JvmMultifileClass
|
||||
|
||||
package test.multiPart
|
||||
|
||||
fun other() {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
@file:JvmName("MultiPart")
|
||||
@file:JvmMultifileClass
|
||||
|
||||
package test.multiPart
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
+2
@@ -1,3 +1,5 @@
|
||||
package simple
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
|
||||
}
|
||||
@@ -1,3 +1,17 @@
|
||||
<problems>
|
||||
<problem>
|
||||
<file>part2A.kt</file>
|
||||
<line>6</line>
|
||||
<entry_point TYPE="file" FQNAME="part2A.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused symbol</problem_class>
|
||||
<description>Function ''other'' is never used</description>
|
||||
</problem>
|
||||
|
||||
<problem>
|
||||
<file>part1B.kt</file>
|
||||
<line>6</line>
|
||||
<entry_point TYPE="file" FQNAME="part1B.kt" />
|
||||
<problem_class severity="WARNING" attribute_key="NOT_USED_ELEMENT_ATTRIBUTES">Unused symbol</problem_class>
|
||||
<description>Function ''other'' is never used</description>
|
||||
</problem>
|
||||
</problems>
|
||||
Reference in New Issue
Block a user