Search in sources :

Example 1 with ContainerForTests

use of org.jetbrains.kotlin.tests.di.ContainerForTests 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)

Example 2 with ContainerForTests

use of org.jetbrains.kotlin.tests.di.ContainerForTests in project kotlin by JetBrains.

the class KotlinTypeCheckerTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    ModuleDescriptorImpl module = KotlinTestUtils.createEmptyModule();
    builtIns = module.getBuiltIns();
    ContainerForTests container = InjectionKt.createContainerForTests(getProject(), module);
    module.setDependencies(Collections.singletonList(module));
    module.initialize(PackageFragmentProvider.Empty.INSTANCE);
    typeResolver = container.getTypeResolver();
    expressionTypingServices = container.getExpressionTypingServices();
    scopeWithImports = getDeclarationsScope("compiler/testData/type-checker-test.kt");
}
Also used : ContainerForTests(org.jetbrains.kotlin.tests.di.ContainerForTests) ModuleDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)

Aggregations

ModuleDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl)2 ContainerForTests (org.jetbrains.kotlin.tests.di.ContainerForTests)2 NotNull (org.jetbrains.annotations.NotNull)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 LexicalScopeImpl (org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1 ExpressionTypingContext (org.jetbrains.kotlin.types.expressions.ExpressionTypingContext)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1