Get rid of split packages in descriptors, descriptors.jvm, deserialization
Also move some other files to related packages and reformat moved files
This commit is contained in:
+1
-1
@@ -1 +1 @@
|
||||
org.jetbrains.kotlin.builtins.BuiltInsLoaderImpl
|
||||
org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInsLoaderImpl
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
|
||||
object BuiltInSerializerProtocol : SerializerExtensionProtocol(
|
||||
ExtensionRegistryLite.newInstance().apply { BuiltInsProtoBuf.registerAllExtensions(this) },
|
||||
BuiltInsProtoBuf.packageFqName,
|
||||
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('.', '/') + "/" + getBuiltInsFileName(fqName)
|
||||
|
||||
fun getBuiltInsFileName(fqName: FqName): String =
|
||||
shortName(fqName) + "." + BUILTINS_FILE_EXTENSION
|
||||
|
||||
private fun shortName(fqName: FqName): String =
|
||||
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProviderImpl
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.AdditionalClassPartsProvider
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.ClassDescriptorFactory
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.PlatformDependentDeclarationFilter
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
class BuiltInsLoaderImpl : BuiltInsLoader {
|
||||
private val resourceLoader = BuiltInsResourceLoader()
|
||||
|
||||
override fun createPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
builtInsModule: ModuleDescriptor,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider
|
||||
): PackageFragmentProvider {
|
||||
return createBuiltInPackageFragmentProvider(
|
||||
storageManager,
|
||||
builtInsModule,
|
||||
KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
classDescriptorFactories,
|
||||
platformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider,
|
||||
resourceLoader::loadResource
|
||||
)
|
||||
}
|
||||
|
||||
fun createBuiltInPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
packageFqNames: Set<FqName>,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
loadResource: (String) -> InputStream?
|
||||
): PackageFragmentProvider {
|
||||
val packageFragments = packageFqNames.map { fqName ->
|
||||
val resourcePath = BuiltInSerializerProtocol.getBuiltInsFilePath(fqName)
|
||||
val inputStream = loadResource(resourcePath) ?: throw IllegalStateException("Resource not found in classpath: $resourcePath")
|
||||
BuiltInsPackageFragmentImpl(fqName, storageManager, module, inputStream)
|
||||
}
|
||||
val provider = PackageFragmentProviderImpl(packageFragments)
|
||||
|
||||
val notFoundClasses = NotFoundClasses(storageManager, module)
|
||||
|
||||
val components = DeserializationComponents(
|
||||
storageManager,
|
||||
module,
|
||||
DeserializationConfiguration.Default,
|
||||
DeserializedClassDataFinder(provider),
|
||||
AnnotationAndConstantLoaderImpl(module, notFoundClasses, BuiltInSerializerProtocol),
|
||||
provider,
|
||||
LocalClassifierTypeSettings.Default,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
classDescriptorFactories,
|
||||
notFoundClasses,
|
||||
ContractDeserializer.DEFAULT,
|
||||
additionalClassPartsProvider,
|
||||
platformDependentDeclarationFilter,
|
||||
BuiltInSerializerProtocol.extensionRegistry
|
||||
)
|
||||
|
||||
for (packageFragment in packageFragments) {
|
||||
packageFragment.initialize(components)
|
||||
}
|
||||
|
||||
return provider
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
class BuiltInsPackageFragmentImpl(
|
||||
fqName: FqName,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
inputStream: InputStream
|
||||
) : BuiltInsPackageFragment, DeserializedPackageFragmentImpl(fqName, storageManager, module, inputStream.use { stream ->
|
||||
val version = BuiltInsBinaryVersion.readFrom(stream)
|
||||
|
||||
if (!version.isCompatible()) {
|
||||
// TODO: report a proper diagnostic
|
||||
throw UnsupportedOperationException(
|
||||
"Kotlin built-in definition format version is not supported: " +
|
||||
"expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " +
|
||||
"Please update Kotlin"
|
||||
)
|
||||
}
|
||||
|
||||
ProtoBuf.PackageFragment.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
|
||||
}, containerSource = null)
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2017 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 java.io.InputStream
|
||||
|
||||
class BuiltInsResourceLoader {
|
||||
fun loadResource(path: String): InputStream? {
|
||||
return this::class.java.classLoader?.getResourceAsStream(path)
|
||||
?: ClassLoader.getSystemResourceAsStream(path)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -16,7 +16,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization
|
||||
|
||||
import org.jetbrains.kotlin.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.descriptors.PackagePartProvider
|
||||
@@ -32,6 +31,7 @@ import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.scopes.ChainedMemberScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerializerProtocol
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPackageMemberScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.builtins
|
||||
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
|
||||
object BuiltInSerializerProtocol : SerializerExtensionProtocol(
|
||||
ExtensionRegistryLite.newInstance().apply { BuiltInsProtoBuf.registerAllExtensions(this) },
|
||||
BuiltInsProtoBuf.packageFqName,
|
||||
BuiltInsProtoBuf.constructorAnnotation, BuiltInsProtoBuf.classAnnotation, BuiltInsProtoBuf.functionAnnotation,
|
||||
BuiltInsProtoBuf.propertyAnnotation, BuiltInsProtoBuf.enumEntryAnnotation, BuiltInsProtoBuf.compileTimeValue,
|
||||
BuiltInsProtoBuf.parameterAnnotation, BuiltInsProtoBuf.typeAnnotation, BuiltInsProtoBuf.typeParameterAnnotation
|
||||
) {
|
||||
const val BUILTINS_FILE_EXTENSION = "kotlin_builtins"
|
||||
|
||||
fun getBuiltInsFilePath(fqName: FqName): String =
|
||||
fqName.asString().replace('.', '/') + "/" + getBuiltInsFileName(
|
||||
fqName
|
||||
)
|
||||
|
||||
fun getBuiltInsFileName(fqName: FqName): String =
|
||||
shortName(fqName) + "." + BUILTINS_FILE_EXTENSION
|
||||
|
||||
private fun shortName(fqName: FqName): String =
|
||||
if (fqName.isRoot) "default-package" else fqName.shortName().asString()
|
||||
}
|
||||
+87
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.BuiltInsLoader
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.NotFoundClasses
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProvider
|
||||
import org.jetbrains.kotlin.descriptors.PackageFragmentProviderImpl
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.AdditionalClassPartsProvider
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.ClassDescriptorFactory
|
||||
import org.jetbrains.kotlin.descriptors.deserialization.PlatformDependentDeclarationFilter
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
class BuiltInsLoaderImpl : BuiltInsLoader {
|
||||
private val resourceLoader = BuiltInsResourceLoader()
|
||||
|
||||
override fun createPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
builtInsModule: ModuleDescriptor,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider
|
||||
): PackageFragmentProvider {
|
||||
return createBuiltInPackageFragmentProvider(
|
||||
storageManager,
|
||||
builtInsModule,
|
||||
KotlinBuiltIns.BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
classDescriptorFactories,
|
||||
platformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider,
|
||||
resourceLoader::loadResource
|
||||
)
|
||||
}
|
||||
|
||||
fun createBuiltInPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
packageFqNames: Set<FqName>,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider = AdditionalClassPartsProvider.None,
|
||||
loadResource: (String) -> InputStream?
|
||||
): PackageFragmentProvider {
|
||||
val packageFragments = packageFqNames.map { fqName ->
|
||||
val resourcePath = BuiltInSerializerProtocol.getBuiltInsFilePath(fqName)
|
||||
val inputStream = loadResource(resourcePath) ?: throw IllegalStateException("Resource not found in classpath: $resourcePath")
|
||||
BuiltInsPackageFragmentImpl(fqName, storageManager, module, inputStream)
|
||||
}
|
||||
val provider = PackageFragmentProviderImpl(packageFragments)
|
||||
|
||||
val notFoundClasses = NotFoundClasses(storageManager, module)
|
||||
|
||||
val components = DeserializationComponents(
|
||||
storageManager,
|
||||
module,
|
||||
DeserializationConfiguration.Default,
|
||||
DeserializedClassDataFinder(provider),
|
||||
AnnotationAndConstantLoaderImpl(module, notFoundClasses, BuiltInSerializerProtocol),
|
||||
provider,
|
||||
LocalClassifierTypeSettings.Default,
|
||||
ErrorReporter.DO_NOTHING,
|
||||
LookupTracker.DO_NOTHING,
|
||||
FlexibleTypeDeserializer.ThrowException,
|
||||
classDescriptorFactories,
|
||||
notFoundClasses,
|
||||
ContractDeserializer.DEFAULT,
|
||||
additionalClassPartsProvider,
|
||||
platformDependentDeclarationFilter,
|
||||
BuiltInSerializerProtocol.extensionRegistry
|
||||
)
|
||||
|
||||
for (packageFragment in packageFragments) {
|
||||
packageFragment.initialize(components)
|
||||
}
|
||||
|
||||
return provider
|
||||
}
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.builtins
|
||||
|
||||
import org.jetbrains.kotlin.builtins.BuiltInsPackageFragment
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.builtins.BuiltInsBinaryVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
import java.io.InputStream
|
||||
|
||||
class BuiltInsPackageFragmentImpl(
|
||||
fqName: FqName,
|
||||
storageManager: StorageManager,
|
||||
module: ModuleDescriptor,
|
||||
inputStream: InputStream
|
||||
) : BuiltInsPackageFragment, DeserializedPackageFragmentImpl(fqName, storageManager, module, inputStream.use { stream ->
|
||||
val version = BuiltInsBinaryVersion.readFrom(stream)
|
||||
|
||||
if (!version.isCompatible()) {
|
||||
// TODO: report a proper diagnostic
|
||||
throw UnsupportedOperationException(
|
||||
"Kotlin built-in definition format version is not supported: " +
|
||||
"expected ${BuiltInsBinaryVersion.INSTANCE}, actual $version. " +
|
||||
"Please update Kotlin"
|
||||
)
|
||||
}
|
||||
|
||||
ProtoBuf.PackageFragment.parseFrom(stream, BuiltInSerializerProtocol.extensionRegistry)
|
||||
}, containerSource = null)
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.serialization.deserialization.builtins
|
||||
|
||||
import java.io.InputStream
|
||||
|
||||
class BuiltInsResourceLoader {
|
||||
fun loadResource(path: String): InputStream? {
|
||||
return this::class.java.classLoader?.getResourceAsStream(path)
|
||||
?: ClassLoader.getSystemResourceAsStream(path)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user