Extract logic of builtins package fragment provider creation
This allows to drop the compile dependency of module 'descriptors' on 'deserialization', breaking the circular dependency between them
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* 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.PackageFragmentProvider
|
||||
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.storage.StorageManager
|
||||
import java.util.*
|
||||
|
||||
interface BuiltInsLoader {
|
||||
fun createPackageFragmentProvider(
|
||||
storageManager: StorageManager,
|
||||
builtInsModule: ModuleDescriptor,
|
||||
classDescriptorFactories: Iterable<ClassDescriptorFactory>,
|
||||
platformDependentDeclarationFilter: PlatformDependentDeclarationFilter,
|
||||
additionalClassPartsProvider: AdditionalClassPartsProvider
|
||||
): PackageFragmentProvider
|
||||
|
||||
companion object {
|
||||
val Instance: BuiltInsLoader =
|
||||
ServiceLoader.load(BuiltInsLoader::class.java, BuiltInsLoader::class.java.classLoader).first()
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,6 @@ import org.jetbrains.kotlin.storage.StorageManager;
|
||||
import org.jetbrains.kotlin.types.*;
|
||||
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
|
||||
import static kotlin.collections.SetsKt.setOf;
|
||||
@@ -135,21 +134,10 @@ public abstract class KotlinBuiltIns {
|
||||
|
||||
protected void createBuiltInsModule() {
|
||||
builtInsModule = new ModuleDescriptorImpl(BUILTINS_MODULE_NAME, storageManager, this, null);
|
||||
PackageFragmentProvider packageFragmentProvider = BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(
|
||||
storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES,
|
||||
getClassDescriptorFactories(),
|
||||
getPlatformDependentDeclarationFilter(),
|
||||
getAdditionalClassPartsProvider(),
|
||||
new Function1<String, InputStream>() {
|
||||
@Override
|
||||
public InputStream invoke(String path) {
|
||||
ClassLoader classLoader = KotlinBuiltIns.class.getClassLoader();
|
||||
return classLoader != null ? classLoader.getResourceAsStream(path) : ClassLoader.getSystemResourceAsStream(path);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
builtInsModule.initialize(packageFragmentProvider);
|
||||
builtInsModule.initialize(BuiltInsLoader.Companion.getInstance().createPackageFragmentProvider(
|
||||
storageManager, builtInsModule,
|
||||
getClassDescriptorFactories(), getPlatformDependentDeclarationFilter(), getAdditionalClassPartsProvider()
|
||||
));
|
||||
builtInsModule.setDependencies(builtInsModule);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user