Improve package class naming for -produce framework
Don't include common package to the name
This commit is contained in:
committed by
SvyatoslavScherbina
parent
5ade7505b3
commit
b5e81a8008
+1
-1
@@ -157,7 +157,7 @@ internal class ObjCExport(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ModuleDescriptor.guessMainPackage(): FqName {
|
internal fun ModuleDescriptor.guessMainPackage(): FqName {
|
||||||
val allPackages = this.getPackageFragments() // Includes also all parent packages, e.g. the root one.
|
val allPackages = this.getPackageFragments() // Includes also all parent packages, e.g. the root one.
|
||||||
|
|
||||||
val nonEmptyPackages = allPackages
|
val nonEmptyPackages = allPackages
|
||||||
|
|||||||
+11
-6
@@ -30,6 +30,9 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf
|
|||||||
internal class ObjCExportNamer(val context: Context, val mapper: ObjCExportMapper) {
|
internal class ObjCExportNamer(val context: Context, val mapper: ObjCExportMapper) {
|
||||||
val kotlinAnyName = "KotlinBase"
|
val kotlinAnyName = "KotlinBase"
|
||||||
|
|
||||||
|
private val commonPackageSegments = context.moduleDescriptor.guessMainPackage().pathSegments()
|
||||||
|
private val topLevelNamePrefix = context.moduleDescriptor.namePrefix
|
||||||
|
|
||||||
private val methodSelectors = object : Mapping<FunctionDescriptor, String>() {
|
private val methodSelectors = object : Mapping<FunctionDescriptor, String>() {
|
||||||
override fun conflict(first: FunctionDescriptor, second: FunctionDescriptor): Boolean =
|
override fun conflict(first: FunctionDescriptor, second: FunctionDescriptor): Boolean =
|
||||||
!mapper.canHaveSameSelector(first, second)
|
!mapper.canHaveSameSelector(first, second)
|
||||||
@@ -56,11 +59,13 @@ internal class ObjCExportNamer(val context: Context, val mapper: ObjCExportMappe
|
|||||||
|
|
||||||
fun getPackageName(fqName: FqName): String = classNames.getOrPut(fqName) {
|
fun getPackageName(fqName: FqName): String = classNames.getOrPut(fqName) {
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
append(context.moduleDescriptor.namePrefix)
|
append(topLevelNamePrefix)
|
||||||
if (fqName.isRoot) {
|
fqName.pathSegments().forEachIndexed { index, segment ->
|
||||||
append("TopLevel")
|
if (index < commonPackageSegments.size) {
|
||||||
} else {
|
assert(commonPackageSegments[index] == segment)
|
||||||
append(fqName.pathSegments().joinToString("") { it.asString().capitalize() })
|
} else {
|
||||||
|
append(segment.asString().capitalize())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.mangledSequence { append("_") }
|
}.mangledSequence { append("_") }
|
||||||
}
|
}
|
||||||
@@ -70,7 +75,7 @@ internal class ObjCExportNamer(val context: Context, val mapper: ObjCExportMappe
|
|||||||
|
|
||||||
return mapping.getOrPut(descriptor) {
|
return mapping.getOrPut(descriptor) {
|
||||||
StringBuilder().apply {
|
StringBuilder().apply {
|
||||||
append(context.moduleDescriptor.namePrefix)
|
append(topLevelNamePrefix)
|
||||||
|
|
||||||
if (descriptor.module != context.moduleDescriptor) {
|
if (descriptor.module != context.moduleDescriptor) {
|
||||||
append(descriptor.module.namePrefix)
|
append(descriptor.module.namePrefix)
|
||||||
|
|||||||
Reference in New Issue
Block a user