use of org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl in project kotlin by JetBrains.
the class JsConfig method createModuleDescriptor.
private JsModuleDescriptor<ModuleDescriptorImpl> createModuleDescriptor(KotlinJavascriptMetadata metadata) {
assert metadata.getVersion().isCompatible() : "Expected JS metadata version " + JsMetadataVersion.INSTANCE + ", but actual metadata version is " + metadata.getVersion();
ModuleDescriptorImpl moduleDescriptor = new ModuleDescriptorImpl(Name.special("<" + metadata.getModuleName() + ">"), storageManager, JsPlatform.INSTANCE.getBuiltIns());
JsModuleDescriptor<PackageFragmentProvider> rawDescriptor = KotlinJavascriptSerializationUtil.readModule(metadata.getBody(), storageManager, moduleDescriptor, new CompilerDeserializationConfiguration(CommonConfigurationKeysKt.getLanguageVersionSettings(configuration)));
PackageFragmentProvider provider = rawDescriptor.getData();
moduleDescriptor.initialize(provider != null ? provider : PackageFragmentProvider.Empty.INSTANCE);
return rawDescriptor.copy(moduleDescriptor);
}
use of org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl in project kotlin by JetBrains.
the class JsConfig method getModuleDescriptors.
@NotNull
public List<JsModuleDescriptor<ModuleDescriptorImpl>> getModuleDescriptors() {
init();
if (moduleDescriptors != null)
return moduleDescriptors;
moduleDescriptors = new SmartList<JsModuleDescriptor<ModuleDescriptorImpl>>();
List<ModuleDescriptorImpl> kotlinModuleDescriptors = new ArrayList<ModuleDescriptorImpl>();
for (KotlinJavascriptMetadata metadataEntry : metadata) {
JsModuleDescriptor<ModuleDescriptorImpl> descriptor = createModuleDescriptor(metadataEntry);
moduleDescriptors.add(descriptor);
kotlinModuleDescriptors.add(descriptor.getData());
}
for (JsModuleDescriptor<ModuleDescriptorImpl> module : moduleDescriptors) {
// TODO: remove downcast
setDependencies(module.getData(), kotlinModuleDescriptors);
}
moduleDescriptors = Collections.unmodifiableList(moduleDescriptors);
return moduleDescriptors;
}
use of org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl in project kotlin by JetBrains.
the class LoadBuiltinsTest method createBuiltInsPackageFragmentProvider.
@NotNull
private static PackageFragmentProvider createBuiltInsPackageFragmentProvider() {
LockBasedStorageManager storageManager = new LockBasedStorageManager();
ModuleDescriptorImpl builtInsModule = new ModuleDescriptorImpl(KotlinBuiltIns.BUILTINS_MODULE_NAME, storageManager, DefaultBuiltIns.getInstance());
PackageFragmentProvider packageFragmentProvider = createBuiltInPackageFragmentProvider(storageManager, builtInsModule, BUILT_INS_PACKAGE_FQ_NAMES, Collections.singletonList(new BuiltInFictitiousFunctionClassFactory(storageManager, builtInsModule)), PlatformDependentDeclarationFilter.All.INSTANCE, AdditionalClassPartsProvider.None.INSTANCE, new Function1<String, InputStream>() {
@Override
public InputStream invoke(String path) {
return ForTestCompileRuntime.runtimeJarClassLoader().getResourceAsStream(path);
}
});
builtInsModule.initialize(packageFragmentProvider);
builtInsModule.setDependencies(builtInsModule);
return packageFragmentProvider;
}
use of org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl in project kotlin by JetBrains.
the class KotlinBuiltIns method createBuiltInsModule.
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.setDependencies(builtInsModule);
}
use of org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl in project kotlin by JetBrains.
the class ExpectedResolveDataUtil method standardFunction.
@NotNull
private static FunctionDescriptor standardFunction(ClassDescriptor classDescriptor, String name, Project project, KotlinType... parameterTypes) {
ModuleDescriptorImpl emptyModule = KotlinTestUtils.createEmptyModule();
ContainerForTests container = InjectionKt.createContainerForTests(project, emptyModule);
emptyModule.setDependencies(emptyModule);
emptyModule.initialize(PackageFragmentProvider.Empty.INSTANCE);
LexicalScopeImpl lexicalScope = new LexicalScopeImpl(ImportingScope.Empty.INSTANCE, classDescriptor, false, classDescriptor.getThisAsReceiverParameter(), LexicalScopeKind.SYNTHETIC);
ExpressionTypingContext context = ExpressionTypingContext.newContext(new BindingTraceContext(), lexicalScope, DataFlowInfoFactory.EMPTY, TypeUtils.NO_EXPECTED_TYPE);
KtExpression callElement = KtPsiFactory(project).createExpression(name);
TemporaryBindingTrace traceWithFakeArgumentInfo = TemporaryBindingTrace.create(context.trace, "trace to store fake argument for", name);
List<KtExpression> fakeArguments = new ArrayList<KtExpression>(parameterTypes.length);
for (KotlinType type : parameterTypes) {
fakeArguments.add(ExpressionTypingUtils.createFakeExpressionOfType(project, traceWithFakeArgumentInfo, "fakeArgument" + fakeArguments.size(), type));
}
OverloadResolutionResults<FunctionDescriptor> functions = container.getFakeCallResolver().resolveFakeCall(context, null, Name.identifier(name), callElement, callElement, FakeCallKind.OTHER, fakeArguments);
for (ResolvedCall<? extends FunctionDescriptor> resolvedCall : functions.getResultingCalls()) {
List<ValueParameterDescriptor> unsubstitutedValueParameters = resolvedCall.getResultingDescriptor().getValueParameters();
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
if (unsubstitutedValueParameter.getType().equals(parameterTypes[i])) {
return resolvedCall.getResultingDescriptor();
}
}
}
throw new IllegalArgumentException("Not found: kotlin::" + classDescriptor.getName() + "." + name + "(" + Arrays.toString(parameterTypes) + ")");
}
Aggregations