Move builtins-related logic from DeserializedPackageFragment to BuiltinsPackageFragment
This commit is contained in:
+6
-1
@@ -17,10 +17,12 @@
|
||||
package org.jetbrains.kotlin.serialization.js
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.serialization.ProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment
|
||||
import org.jetbrains.kotlin.serialization.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
@@ -30,10 +32,13 @@ public class KotlinJavascriptPackageFragment(
|
||||
module: ModuleDescriptor,
|
||||
loadResource: (path: String) -> InputStream?
|
||||
) : DeserializedPackageFragment(fqName, storageManager, module, KotlinJavascriptSerializedResourcePaths, loadResource) {
|
||||
override val nameResolver = NameResolverImpl.read(loadResourceSure(serializedResourcePaths.getStringTableFilePath(fqName)))
|
||||
|
||||
override val classIdToProto: Map<ClassId, ProtoBuf.Class>? get() = null
|
||||
|
||||
protected override fun loadClassNames(packageProto: ProtoBuf.Package): Collection<Name> {
|
||||
val classesStream = loadResourceSure(KotlinJavascriptSerializedResourcePaths.getClassesInPackageFilePath(fqName))
|
||||
val classesProto = JsProtoBuf.Classes.parseFrom(classesStream, serializedResourcePaths.extensionRegistry)
|
||||
return classesProto.getClassNameList()?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||
return classesProto.classNameList?.map { id -> nameResolver.getName(id) } ?: listOf()
|
||||
}
|
||||
}
|
||||
|
||||
+5
-8
@@ -37,7 +37,7 @@ object KotlinJavascriptSerializedResourcePaths : SerializedResourcePaths {
|
||||
|
||||
|
||||
override fun getClassMetadataPath(classId: ClassId): String {
|
||||
return classId.getPackageFqName().toPath().withSepIfNotEmpty() + classId.getRelativeClassName().asString() +
|
||||
return classId.packageFqName.toPath().withSepIfNotEmpty() + classId.relativeClassName.asString() +
|
||||
"." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
}
|
||||
|
||||
@@ -47,14 +47,12 @@ object KotlinJavascriptSerializedResourcePaths : SerializedResourcePaths {
|
||||
override fun getStringTableFilePath(fqName: FqName): String =
|
||||
fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + STRING_TABLE_FILE_EXTENSION
|
||||
|
||||
override fun getBuiltInsFilePath(fqName: FqName): String? = null
|
||||
|
||||
private fun FqName.toPath() = this.asString().replace('.', '/')
|
||||
|
||||
private fun String.withSepIfNotEmpty() = if (this.isEmpty()) this else this + "/"
|
||||
|
||||
private fun shortName(fqName: FqName): String =
|
||||
if (fqName.isRoot()) "default-package" else fqName.shortName().asString()
|
||||
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
|
||||
|
||||
}
|
||||
|
||||
@@ -62,7 +60,7 @@ private val PACKAGE_CLASS_NAME_SUFFIX: String = "Package"
|
||||
private val DEFAULT_PACKAGE_CLASS_NAME: String = "_Default" + PACKAGE_CLASS_NAME_SUFFIX
|
||||
private val DEFAULT_PACKAGE_METAFILE_NAME: String = DEFAULT_PACKAGE_CLASS_NAME + "." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
|
||||
|
||||
public fun FqName.isPackageClassFqName(): Boolean = !this.isRoot() && getPackageClassFqName(this.parent()) == this
|
||||
public fun FqName.isPackageClassFqName(): Boolean = !this.isRoot && getPackageClassFqName(this.parent()) == this
|
||||
|
||||
public fun isDefaultPackageMetafile(fileName: String): Boolean = fileName == DEFAULT_PACKAGE_METAFILE_NAME
|
||||
|
||||
@@ -85,10 +83,9 @@ private fun getPackageClassFqName(packageFQN: FqName): FqName {
|
||||
}
|
||||
|
||||
private fun getPackageClassName(packageFQN: FqName): String {
|
||||
return if (packageFQN.isRoot()) DEFAULT_PACKAGE_CLASS_NAME else capitalizeNonEmptyString(packageFQN.shortName().asString()) + PACKAGE_CLASS_NAME_SUFFIX
|
||||
return if (packageFQN.isRoot) DEFAULT_PACKAGE_CLASS_NAME else capitalizeNonEmptyString(packageFQN.shortName().asString()) + PACKAGE_CLASS_NAME_SUFFIX
|
||||
}
|
||||
|
||||
private fun capitalizeNonEmptyString(s: String): String {
|
||||
return if (Character.isUpperCase(s.charAt(0))) s else Character.toUpperCase(s.charAt(0)) + s.substring(1)
|
||||
return if (s[0].isUpperCase()) s else s[0].toUpperCase() + s.substring(1)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user