Remove SerializedResourcePaths and BuiltInsSerializedResourcePaths

Most of members now only make sense for JS, move the rest to
BuiltInSerializerProtocol
This commit is contained in:
Alexander Udalov
2016-02-17 15:37:14 +03:00
committed by Alexander Udalov
parent 4bacabe354
commit f82ec6711d
16 changed files with 38 additions and 122 deletions
@@ -21,8 +21,8 @@ import com.intellij.openapi.util.Disposer
import com.intellij.psi.search.GlobalSearchScope
import org.jetbrains.kotlin.analyzer.ModuleContent
import org.jetbrains.kotlin.analyzer.ModuleInfo
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion
import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths
import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys
import org.jetbrains.kotlin.cli.common.messages.MessageCollector
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
@@ -162,7 +162,7 @@ class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
version.forEach { writeInt(it) }
}
proto.build().writeTo(stream)
write(BuiltInsSerializedResourcePaths.getBuiltInsFilePath(fqName), stream)
write(BuiltInSerializerProtocol.getBuiltInsFilePath(fqName), stream)
}
private fun write(fileName: String, stream: ByteArrayOutputStream) {
@@ -16,11 +16,22 @@
package org.jetbrains.kotlin.builtins
import com.google.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
object BuiltInSerializerProtocol : SerializerExtensionProtocol(
ExtensionRegistryLite.newInstance().apply { BuiltInsProtoBuf.registerAllExtensions(this) },
BuiltInsProtoBuf.constructorAnnotation, BuiltInsProtoBuf.classAnnotation, BuiltInsProtoBuf.functionAnnotation,
BuiltInsProtoBuf.propertyAnnotation, BuiltInsProtoBuf.enumEntryAnnotation, BuiltInsProtoBuf.compileTimeValue,
BuiltInsProtoBuf.parameterAnnotation, BuiltInsProtoBuf.typeAnnotation, BuiltInsProtoBuf.typeParameterAnnotation
)
) {
val BUILTINS_FILE_EXTENSION = "kotlin_builtins"
fun getBuiltInsFilePath(fqName: FqName): String =
fqName.asString().replace('.', '/') + "/" + shortName(fqName) + "." + BUILTINS_FILE_EXTENSION
private fun shortName(fqName: FqName): String =
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
}
@@ -1,58 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.builtins
import com.google.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.serialization.SerializedResourcePaths
import org.jetbrains.kotlin.serialization.builtins.BuiltInsProtoBuf
object BuiltInsSerializedResourcePaths : SerializedResourcePaths {
override val extensionRegistry: ExtensionRegistryLite
init {
extensionRegistry = ExtensionRegistryLite.newInstance()
BuiltInsProtoBuf.registerAllExtensions(extensionRegistry)
}
val CLASS_METADATA_FILE_EXTENSION = "kotlin_class"
val PACKAGE_FILE_EXTENSION = "kotlin_package"
val STRING_TABLE_FILE_EXTENSION = "kotlin_string_table"
val BUILTINS_FILE_EXTENSION = "kotlin_builtins"
override fun getClassMetadataPath(classId: ClassId): String {
return packageFqNameToPath(classId.packageFqName) + "/" + classId.relativeClassName.asString() +
"." + CLASS_METADATA_FILE_EXTENSION
}
override fun getPackageFilePath(fqName: FqName): String =
packageFqNameToPath(fqName) + "/" + shortName(fqName) + "." + PACKAGE_FILE_EXTENSION
override fun getStringTableFilePath(fqName: FqName): String =
packageFqNameToPath(fqName) + "/" + shortName(fqName) + "." + STRING_TABLE_FILE_EXTENSION
fun getBuiltInsFilePath(fqName: FqName): String =
packageFqNameToPath(fqName) + "/" + shortName(fqName) + "." + BUILTINS_FILE_EXTENSION
private fun packageFqNameToPath(fqName: FqName): String =
fqName.asString().replace('.', '/')
private fun shortName(fqName: FqName): String =
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
}
@@ -32,7 +32,7 @@ class BuiltinsPackageFragment(
loadResource: (path: String) -> InputStream?
) : DeserializedPackageFragment(fqName, storageManager, module, loadResource) {
private val proto = run {
val stream = loadResourceSure(BuiltInsSerializedResourcePaths.getBuiltInsFilePath(fqName))
val stream = loadResourceSure(BuiltInSerializerProtocol.getBuiltInsFilePath(fqName))
val version = BuiltInsBinaryVersion.readFrom(stream)
if (!version.isCompatible()) {
@@ -44,7 +44,7 @@ class BuiltinsPackageFragment(
)
}
BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInsSerializedResourcePaths.extensionRegistry)
BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
}
private val nameResolver = NameResolverImpl(proto.strings, proto.qualifiedNames)
@@ -1,31 +0,0 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.serialization
import com.google.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
interface SerializedResourcePaths {
val extensionRegistry: ExtensionRegistryLite
fun getClassMetadataPath(classId: ClassId): String
fun getPackageFilePath(fqName: FqName): String
fun getStringTableFilePath(fqName: FqName): String
}
@@ -16,9 +16,11 @@
package org.jetbrains.kotlin.serialization;
import com.google.protobuf.ExtensionRegistryLite
import com.google.protobuf.GeneratedMessageLite.GeneratedExtension
open class SerializerExtensionProtocol(
val extensionRegistry: ExtensionRegistryLite,
val constructorAnnotation: GeneratedExtension<ProtoBuf.Constructor, List<ProtoBuf.Annotation>>,
val classAnnotation: GeneratedExtension<ProtoBuf.Class, List<ProtoBuf.Annotation>>,
val functionAnnotation: GeneratedExtension<ProtoBuf.Function, List<ProtoBuf.Annotation>>,
@@ -22,8 +22,8 @@ import com.intellij.psi.FileViewProvider
import com.intellij.psi.PsiManager
import com.intellij.psi.compiled.ClassFileDecompilers
import org.jetbrains.annotations.TestOnly
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.builtins.BuiltInsBinaryVersion
import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.decompiler.KotlinDecompiledFileViewProvider
import org.jetbrains.kotlin.idea.decompiler.KtDecompiledFile
@@ -127,7 +127,7 @@ sealed class BuiltInDefinitionFile {
return BuiltInDefinitionFile.Incompatible(version)
}
val proto = BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInsSerializedResourcePaths.extensionRegistry)
val proto = BuiltInsProtoBuf.BuiltIns.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
return BuiltInDefinitionFile.Compatible(proto, file.parent)
}
}
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.decompiler.builtIns
import com.intellij.openapi.fileTypes.FileType
import com.intellij.openapi.vfs.VirtualFile
import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.idea.KotlinIcons
object KotlinBuiltInFileType : FileType {
@@ -26,7 +26,7 @@ object KotlinBuiltInFileType : FileType {
override fun getDescription() = "Kotlin built-in declarations"
override fun getDefaultExtension() = BuiltInsSerializedResourcePaths.BUILTINS_FILE_EXTENSION
override fun getDefaultExtension() = BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION
override fun getIcon() = KotlinIcons.FILE
@@ -73,7 +73,7 @@ class KotlinJavaScriptDeserializerForDecompiler(
}
val content = file.contentsToByteArray(false)
val packageProto = ProtoBuf.Package.parseFrom(content, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
val membersScope = DeserializedPackageMemberScope(
createDummyPackageFragment(packageFqName), packageProto, nameResolver, packagePartSource = null,
components = deserializationComponents
@@ -61,12 +61,12 @@ class KotlinJavaScriptStubBuilder : ClsStubBuilder() {
val components = createStubBuilderComponents(file, nameResolver)
if (isPackageHeader) {
val packageProto = ProtoBuf.Package.parseFrom(content, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val packageProto = ProtoBuf.Package.parseFrom(content, JsSerializerProtocol.extensionRegistry)
val context = components.createContext(nameResolver, packageFqName, TypeTable(packageProto.typeTable))
return createPackageFacadeStub(packageProto, packageFqName, context)
}
else {
val classProto = ProtoBuf.Class.parseFrom(content, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val classProto = ProtoBuf.Class.parseFrom(content, JsSerializerProtocol.extensionRegistry)
val context = components.createContext(nameResolver, packageFqName, TypeTable(classProto.typeTable))
val classId = JsMetaFileUtils.getClassId(file)
return createTopLevelClassStub(classId, classProto, context)
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.psi.search.GlobalSearchScope
import com.intellij.util.indexing.FileContentImpl
import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.idea.caches.IDEKotlinBinaryClassCache
import org.jetbrains.kotlin.idea.decompiler.builtIns.BuiltInDefinitionFile
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInDecompiler
@@ -62,7 +62,7 @@ class BuiltInDecompilerConsistencyTest : KotlinLightCodeInsightFixtureTestCase()
val dir = findDir(packageFqName, project)
val groupedByExtension = dir.children.groupBy { it.extension }
val classFiles = groupedByExtension[JavaClassFileType.INSTANCE.defaultExtension]!!.map { it.nameWithoutExtension }
val builtInsFile = groupedByExtension[BuiltInsSerializedResourcePaths.BUILTINS_FILE_EXTENSION]!!.single()
val builtInsFile = groupedByExtension[BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION]!!.single()
val builtInFileStub = builtInsDecompiler.stubBuilder.buildFileStub(FileContentImpl.createByFile(builtInsFile))!!
@@ -18,7 +18,7 @@ package org.jetbrains.kotlin.idea.decompiler.stubBuilder
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
import com.intellij.util.indexing.FileContentImpl
import org.jetbrains.kotlin.builtins.BuiltInsSerializedResourcePaths
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
import org.jetbrains.kotlin.idea.decompiler.builtIns.KotlinBuiltInStubBuilder
import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor
import org.jetbrains.kotlin.psi.stubs.elements.KtFileStubBuilder
@@ -32,9 +32,7 @@ class BuiltInDecompilerTest : LightCodeInsightFixtureTestCase() {
private fun doTest(packageFqName: String) {
val dirInRuntime = findDir(packageFqName, project)
val kotlinBuiltInsVirtualFile = dirInRuntime.children.single {
it.extension == BuiltInsSerializedResourcePaths.BUILTINS_FILE_EXTENSION
}
val kotlinBuiltInsVirtualFile = dirInRuntime.children.single { it.extension == BuiltInSerializerProtocol.BUILTINS_FILE_EXTENSION }
val stubTreeFromDecompiler = KotlinBuiltInStubBuilder().buildFileStub(FileContentImpl.createByFile(kotlinBuiltInsVirtualFile))!!
myFixture.configureFromExistingVirtualFile(kotlinBuiltInsVirtualFile)
@@ -30,7 +30,7 @@ class KotlinJavascriptClassDataFinder(
) : ClassDataFinder {
override fun findClassData(classId: ClassId): ClassDataWithSource? {
val stream = loadResource(KotlinJavascriptSerializedResourcePaths.getClassMetadataPath(classId)) ?: return null
val classProto = ProtoBuf.Class.parseFrom(stream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val classProto = ProtoBuf.Class.parseFrom(stream, JsSerializerProtocol.extensionRegistry)
return ClassDataWithSource(ClassData(nameResolver, classProto))
}
}
@@ -39,7 +39,7 @@ class KotlinJavascriptPackageFragment(
override fun computeMemberScope(): DeserializedPackageMemberScope {
val packageStream = loadResourceSure(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName))
val packageProto = ProtoBuf.Package.parseFrom(packageStream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val packageProto = ProtoBuf.Package.parseFrom(packageStream, JsSerializerProtocol.extensionRegistry)
return DeserializedPackageMemberScope(
this, packageProto, nameResolver, packagePartSource = null, components = components, classNames = { loadClassNames() }
)
@@ -47,7 +47,7 @@ class KotlinJavascriptPackageFragment(
private fun loadClassNames(): Collection<Name> {
val classesStream = loadResourceSure(KotlinJavascriptSerializedResourcePaths.getClassesInPackageFilePath(fqName))
val classesProto = JsProtoBuf.Classes.parseFrom(classesStream, KotlinJavascriptSerializedResourcePaths.extensionRegistry)
val classesProto = JsProtoBuf.Classes.parseFrom(classesStream, JsSerializerProtocol.extensionRegistry)
return classesProto.classNameList?.map { id -> nameResolver.getName(id) } ?: listOf()
}
}
@@ -16,19 +16,11 @@
package org.jetbrains.kotlin.serialization.js
import com.google.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.serialization.SerializedResourcePaths
object KotlinJavascriptSerializedResourcePaths : SerializedResourcePaths {
override val extensionRegistry: ExtensionRegistryLite = ExtensionRegistryLite.newInstance()
init {
JsProtoBuf.registerAllExtensions(extensionRegistry)
}
object KotlinJavascriptSerializedResourcePaths {
private val CLASSES_FILE_EXTENSION = "kotlin_classes"
private val STRING_TABLE_FILE_EXTENSION = "kotlin_string_table"
@@ -36,15 +28,15 @@ object KotlinJavascriptSerializedResourcePaths : SerializedResourcePaths {
fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + CLASSES_FILE_EXTENSION
override fun getClassMetadataPath(classId: ClassId): String {
fun getClassMetadataPath(classId: ClassId): String {
return classId.packageFqName.toPath().withSepIfNotEmpty() + classId.relativeClassName.asString() +
"." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
}
override fun getPackageFilePath(fqName: FqName): String =
fun getPackageFilePath(fqName: FqName): String =
getPackageClassFqName(fqName).toPath() + "." + KotlinJavascriptSerializationUtil.CLASS_METADATA_FILE_EXTENSION
override fun getStringTableFilePath(fqName: FqName): String =
fun getStringTableFilePath(fqName: FqName): String =
fqName.toPath().withSepIfNotEmpty() + shortName(fqName) + "." + STRING_TABLE_FILE_EXTENSION
private fun FqName.toPath() = this.asString().replace('.', '/')
@@ -16,12 +16,14 @@
package org.jetbrains.kotlin.serialization.js
import com.google.protobuf.ExtensionRegistryLite
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
class KotlinJavascriptSerializerExtension : KotlinSerializerExtensionBase(JsSerializerProtocol)
object JsSerializerProtocol : SerializerExtensionProtocol(
ExtensionRegistryLite.newInstance().apply { JsProtoBuf.registerAllExtensions(this) },
JsProtoBuf.constructorAnnotation, JsProtoBuf.classAnnotation, JsProtoBuf.functionAnnotation, JsProtoBuf.propertyAnnotation,
JsProtoBuf.enumEntryAnnotation, JsProtoBuf.compileTimeValue, JsProtoBuf.parameterAnnotation, JsProtoBuf.typeAnnotation,
JsProtoBuf.typeParameterAnnotation