Filter out package members from other facades in KPackageImpl
#KT-10690 Fixed
This commit is contained in:
@@ -0,0 +1,24 @@
|
|||||||
|
// WITH_REFLECT
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
fun test2() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: main.kt
|
||||||
|
|
||||||
|
import kotlin.reflect.jvm.javaMethod
|
||||||
|
import kotlin.reflect.jvm.kotlinFunction
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (::box.javaMethod?.kotlinFunction == null)
|
||||||
|
return "Fail box"
|
||||||
|
if (::test1.javaMethod?.kotlinFunction == null)
|
||||||
|
return "Fail test1"
|
||||||
|
if (::test2.javaMethod?.kotlinFunction == null)
|
||||||
|
return "Fail test2"
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test1() {
|
||||||
|
}
|
||||||
@@ -83,6 +83,12 @@ public class BlackBoxMultiFileCodegenTestGenerated extends AbstractBlackBoxCodeg
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kt10690.kt")
|
||||||
|
public void testKt10690() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxMultiFile/kt10690.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1515.kt")
|
@TestMetadata("kt1515.kt")
|
||||||
public void testKt1515() throws Exception {
|
public void testKt1515() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxMultiFile/kt1515.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/boxMultiFile/kt1515.kt");
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ class ModuleMapping private constructor(val packageFqName2Parts: Map<String, Pac
|
|||||||
}
|
}
|
||||||
|
|
||||||
class PackageParts(val packageFqName: String) {
|
class PackageParts(val packageFqName: String) {
|
||||||
|
|
||||||
val parts = linkedSetOf<String>()
|
val parts = linkedSetOf<String>()
|
||||||
|
|
||||||
override fun equals(other: Any?) =
|
override fun equals(other: Any?) =
|
||||||
@@ -74,15 +73,18 @@ class PackageParts(val packageFqName: String) {
|
|||||||
override fun hashCode() =
|
override fun hashCode() =
|
||||||
packageFqName.hashCode() * 31 + parts.hashCode()
|
packageFqName.hashCode() * 31 + parts.hashCode()
|
||||||
|
|
||||||
|
override fun toString() =
|
||||||
|
parts.toString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
@JvmStatic
|
||||||
|
fun PackageParts.serialize(builder: JvmPackageTable.PackageTable.Builder) {
|
||||||
if (this.parts.isNotEmpty()) {
|
if (this.parts.isNotEmpty()) {
|
||||||
val packageParts = JvmPackageTable.PackageParts.newBuilder()
|
val packageParts = JvmPackageTable.PackageParts.newBuilder()
|
||||||
packageParts.setPackageFqName(this.packageFqName)
|
packageParts.packageFqName = this.packageFqName
|
||||||
packageParts.addAllClassName(this.parts.sorted())
|
packageParts.addAllClassName(this.parts.sorted())
|
||||||
builder.addPackageParts(packageParts)
|
builder.addPackageParts(packageParts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
|||||||
import java.lang.reflect.Constructor
|
import java.lang.reflect.Constructor
|
||||||
import java.lang.reflect.Method
|
import java.lang.reflect.Method
|
||||||
import kotlin.jvm.internal.ClassBasedDeclarationContainer
|
import kotlin.jvm.internal.ClassBasedDeclarationContainer
|
||||||
import kotlin.reflect.KCallable
|
|
||||||
import kotlin.reflect.KotlinReflectionInternalError
|
import kotlin.reflect.KotlinReflectionInternalError
|
||||||
|
|
||||||
internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContainer {
|
internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContainer {
|
||||||
@@ -45,8 +44,8 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
|||||||
|
|
||||||
abstract fun getFunctions(name: Name): Collection<FunctionDescriptor>
|
abstract fun getFunctions(name: Name): Collection<FunctionDescriptor>
|
||||||
|
|
||||||
fun getMembers(scope: MemberScope, declaredOnly: Boolean, nonExtensions: Boolean, extensions: Boolean): Sequence<KCallable<*>> {
|
fun getMembers(scope: MemberScope, declaredOnly: Boolean, nonExtensions: Boolean, extensions: Boolean): Sequence<KCallableImpl<*>> {
|
||||||
val visitor = object : DeclarationDescriptorVisitorEmptyBodies<KCallable<*>?, Unit>() {
|
val visitor = object : DeclarationDescriptorVisitorEmptyBodies<KCallableImpl<*>?, Unit>() {
|
||||||
private fun skipCallable(descriptor: CallableMemberDescriptor): Boolean {
|
private fun skipCallable(descriptor: CallableMemberDescriptor): Boolean {
|
||||||
if (declaredOnly && !descriptor.kind.isReal) return true
|
if (declaredOnly && !descriptor.kind.isReal) return true
|
||||||
|
|
||||||
@@ -57,15 +56,15 @@ internal abstract class KDeclarationContainerImpl : ClassBasedDeclarationContain
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit): KCallable<*>? {
|
override fun visitPropertyDescriptor(descriptor: PropertyDescriptor, data: Unit): KCallableImpl<*>? {
|
||||||
return if (skipCallable(descriptor)) null else createProperty(descriptor)
|
return if (skipCallable(descriptor)) null else createProperty(descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit): KCallable<*>? {
|
override fun visitFunctionDescriptor(descriptor: FunctionDescriptor, data: Unit): KCallableImpl<*>? {
|
||||||
return if (skipCallable(descriptor)) null else KFunctionImpl(this@KDeclarationContainerImpl, descriptor)
|
return if (skipCallable(descriptor)) null else KFunctionImpl(this@KDeclarationContainerImpl, descriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit): KCallable<*>? {
|
override fun visitConstructorDescriptor(descriptor: ConstructorDescriptor, data: Unit): KCallableImpl<*>? {
|
||||||
throw IllegalStateException("No constructors should appear in this scope: $descriptor")
|
throw IllegalStateException("No constructors should appear in this scope: $descriptor")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,11 +18,16 @@ package kotlin.reflect.jvm.internal
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
import org.jetbrains.kotlin.descriptors.ConstructorDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaPackageFragment
|
||||||
import org.jetbrains.kotlin.load.java.structure.reflect.classId
|
import org.jetbrains.kotlin.load.java.structure.reflect.classId
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryPackageSourceElement
|
||||||
|
import org.jetbrains.kotlin.load.kotlin.reflect.ReflectKotlinClass
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||||
import kotlin.reflect.KCallable
|
import kotlin.reflect.KCallable
|
||||||
|
|
||||||
internal class KPackageImpl(override val jClass: Class<*>, val moduleName: String) : KDeclarationContainerImpl() {
|
internal class KPackageImpl(override val jClass: Class<*>, val moduleName: String) : KDeclarationContainerImpl() {
|
||||||
@@ -36,7 +41,12 @@ internal class KPackageImpl(override val jClass: Class<*>, val moduleName: Strin
|
|||||||
internal val scope: MemberScope get() = descriptor().memberScope
|
internal val scope: MemberScope get() = descriptor().memberScope
|
||||||
|
|
||||||
override val members: Collection<KCallable<*>>
|
override val members: Collection<KCallable<*>>
|
||||||
get() = getMembers(scope, declaredOnly = false, nonExtensions = true, extensions = true).toList()
|
get() = getMembers(scope, declaredOnly = false, nonExtensions = true, extensions = true).filter { member ->
|
||||||
|
val callableDescriptor = member.descriptor as DeserializedCallableMemberDescriptor
|
||||||
|
val packageFragment = callableDescriptor.containingDeclaration as PackageFragmentDescriptor
|
||||||
|
val source = (packageFragment as? LazyJavaPackageFragment)?.source as? KotlinJvmBinaryPackageSourceElement
|
||||||
|
(source?.getContainingBinaryClass(callableDescriptor) as? ReflectKotlinClass)?.klass == jClass
|
||||||
|
}.toList()
|
||||||
|
|
||||||
override val constructorDescriptors: Collection<ConstructorDescriptor>
|
override val constructorDescriptors: Collection<ConstructorDescriptor>
|
||||||
get() = emptyList()
|
get() = emptyList()
|
||||||
|
|||||||
Reference in New Issue
Block a user