Introduce ModuleDescriptor#isFriend(ModuleDescriptor)
Use it to allow friend modules to see internal members
This commit is contained in:
@@ -36,6 +36,8 @@ public trait ModuleDescriptor : DeclarationDescriptor {
|
||||
|
||||
public val platformToKotlinClassMap: PlatformToKotlinClassMap
|
||||
|
||||
public fun isFriend(other: ModuleDescriptor): Boolean
|
||||
|
||||
override fun substitute(substitutor: TypeSubstitutor): ModuleDescriptor {
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class Visibilities {
|
||||
@Override
|
||||
protected boolean isVisible(@NotNull DeclarationDescriptorWithVisibility what, @NotNull DeclarationDescriptor from) {
|
||||
DeclarationDescriptor fromOrModule = from instanceof PackageViewDescriptor ? ((PackageViewDescriptor) from).getModule() : from;
|
||||
return DescriptorUtils.areInSameModule(what, fromOrModule);
|
||||
return isInFriendModule(what, fromOrModule);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -119,6 +119,10 @@ public class Visibilities {
|
||||
return findInvisibleMember(what, from) == null;
|
||||
}
|
||||
|
||||
private static boolean isInFriendModule(@NotNull DeclarationDescriptor what, @NotNull DeclarationDescriptor from) {
|
||||
return DescriptorUtils.getContainingModule(what).isFriend(DescriptorUtils.getContainingModule(from));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static DeclarationDescriptorWithVisibility findInvisibleMember(
|
||||
@NotNull DeclarationDescriptorWithVisibility what,
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotations
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
|
||||
import kotlin.properties.Delegates
|
||||
import java.util.LinkedHashSet
|
||||
|
||||
public class ModuleDescriptorImpl(
|
||||
moduleName: Name,
|
||||
@@ -84,4 +85,14 @@ public class ModuleDescriptorImpl(
|
||||
}
|
||||
|
||||
override fun getPackageFragmentProvider() = packageFragmentProviderForWholeModuleWithDependencies
|
||||
|
||||
private val friendModules = LinkedHashSet<ModuleDescriptor>()
|
||||
|
||||
override fun isFriend(other: ModuleDescriptor) = other == this || other in friendModules
|
||||
|
||||
public fun addFriend(friend: ModuleDescriptorImpl): Unit {
|
||||
assert(friend != this, "Attempt to make module $id a friend to itself")
|
||||
assert(!isSealed, "Attempt to add friend module ${friend.id} to sealed module $id")
|
||||
friendModules.add(friend)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user