Search in sources :

Example 1 with ModuleDescriptorImpl

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);
}
Also used : CompilerDeserializationConfiguration(org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration) PackageFragmentProvider(org.jetbrains.kotlin.descriptors.PackageFragmentProvider) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)

Example 2 with ModuleDescriptorImpl

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;
}
Also used : JsModuleDescriptor(org.jetbrains.kotlin.serialization.js.JsModuleDescriptor) ArrayList(java.util.ArrayList) KotlinJavascriptMetadata(org.jetbrains.kotlin.utils.KotlinJavascriptMetadata) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 3 with ModuleDescriptorImpl

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;
}
Also used : BuiltInFictitiousFunctionClassFactory(org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory) PackageFragmentProvider(org.jetbrains.kotlin.descriptors.PackageFragmentProvider) BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider(org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider) InputStream(java.io.InputStream) LockBasedStorageManager(org.jetbrains.kotlin.storage.LockBasedStorageManager) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with ModuleDescriptorImpl

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);
}
Also used : InputStream(java.io.InputStream) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)

Example 5 with ModuleDescriptorImpl

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) + ")");
}
Also used : LexicalScopeImpl(org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl) KotlinType(org.jetbrains.kotlin.types.KotlinType) ContainerForTests(org.jetbrains.kotlin.tests.di.ContainerForTests) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl) ExpressionTypingContext(org.jetbrains.kotlin.types.expressions.ExpressionTypingContext) KtExpression(org.jetbrains.kotlin.psi.KtExpression) Assert.assertNotNull(org.junit.Assert.assertNotNull) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ModuleDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)6 NotNull (org.jetbrains.annotations.NotNull)3 InputStream (java.io.InputStream)2 PackageFragmentProvider (org.jetbrains.kotlin.descriptors.PackageFragmentProvider)2 ContainerForTests (org.jetbrains.kotlin.tests.di.ContainerForTests)2 ArrayList (java.util.ArrayList)1 BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider (org.jetbrains.kotlin.builtins.BuiltInsPackageFragmentProviderKt.createBuiltInPackageFragmentProvider)1 BuiltInFictitiousFunctionClassFactory (org.jetbrains.kotlin.builtins.functions.BuiltInFictitiousFunctionClassFactory)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 CompilerDeserializationConfiguration (org.jetbrains.kotlin.resolve.CompilerDeserializationConfiguration)1 LexicalScopeImpl (org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl)1 JsModuleDescriptor (org.jetbrains.kotlin.serialization.js.JsModuleDescriptor)1 LockBasedStorageManager (org.jetbrains.kotlin.storage.LockBasedStorageManager)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 ExpressionTypingContext (org.jetbrains.kotlin.types.expressions.ExpressionTypingContext)1 KotlinJavascriptMetadata (org.jetbrains.kotlin.utils.KotlinJavascriptMetadata)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1