Search in sources :

Example 6 with LexicalScope

use of org.jetbrains.kotlin.resolve.scopes.LexicalScope in project kotlin by JetBrains.

the class CallExpressionTranslator method getVariableByName.

@Nullable
private static VariableDescriptor getVariableByName(@NotNull LexicalScope scope, @NotNull Name name) {
    while (true) {
        Collection<VariableDescriptor> variables = scope.getContributedVariables(name, NoLookupLocation.FROM_BACKEND);
        if (!variables.isEmpty()) {
            return variables.size() == 1 ? variables.iterator().next() : null;
        }
        if (!(scope.getParent() instanceof LexicalScope))
            break;
        LexicalScope parentScope = (LexicalScope) scope.getParent();
        if (scope.getOwnerDescriptor() != parentScope.getOwnerDescriptor())
            break;
        scope = parentScope;
    }
    return null;
}
Also used : LexicalScope(org.jetbrains.kotlin.resolve.scopes.LexicalScope) Nullable(org.jetbrains.annotations.Nullable)

Example 7 with LexicalScope

use of org.jetbrains.kotlin.resolve.scopes.LexicalScope in project kotlin by JetBrains.

the class KotlinOverridingTest method makeFunction.

private FunctionDescriptor makeFunction(String funDecl) {
    KtNamedFunction function = KtPsiFactoryKt.KtPsiFactory(getProject()).createFunction(funDecl);
    LexicalScope scope = TypeTestUtilsKt.builtInPackageAsLexicalScope(module);
    return functionDescriptorResolver.resolveFunctionDescriptor(module, scope, function, KotlinTestUtils.DUMMY_TRACE, DataFlowInfoFactory.EMPTY);
}
Also used : LexicalScope(org.jetbrains.kotlin.resolve.scopes.LexicalScope) KtNamedFunction(org.jetbrains.kotlin.psi.KtNamedFunction)

Example 8 with LexicalScope

use of org.jetbrains.kotlin.resolve.scopes.LexicalScope in project kotlin by JetBrains.

the class KotlinTypeCheckerTest method assertType.

private void assertType(String contextType, String expression, String expectedType) {
    KotlinType thisType = makeType(contextType);
    ReceiverParameterDescriptorImpl receiverParameterDescriptor = new ReceiverParameterDescriptorImpl(scopeWithImports.getOwnerDescriptor(), new TransientReceiver(thisType));
    LexicalScope scope = new LexicalScopeImpl(scopeWithImports, scopeWithImports.getOwnerDescriptor(), false, receiverParameterDescriptor, LexicalScopeKind.SYNTHETIC);
    assertType(scope, expression, expectedType);
}
Also used : LexicalScope(org.jetbrains.kotlin.resolve.scopes.LexicalScope) LexicalScopeImpl(org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl) TransientReceiver(org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver) ReceiverParameterDescriptorImpl(org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl)

Aggregations

LexicalScope (org.jetbrains.kotlin.resolve.scopes.LexicalScope)8 NotNull (org.jetbrains.annotations.NotNull)2 KtNamedFunction (org.jetbrains.kotlin.psi.KtNamedFunction)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nullable (org.jetbrains.annotations.Nullable)1 ReceiverParameterDescriptorImpl (org.jetbrains.kotlin.descriptors.impl.ReceiverParameterDescriptorImpl)1 KtExpression (org.jetbrains.kotlin.psi.KtExpression)1 DataFlowInfo (org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo)1 LazyAnnotations (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotations)1 LazyAnnotationsContextImpl (org.jetbrains.kotlin.resolve.lazy.descriptors.LazyAnnotationsContextImpl)1 LexicalScopeImpl (org.jetbrains.kotlin.resolve.scopes.LexicalScopeImpl)1 LexicalWritableScope (org.jetbrains.kotlin.resolve.scopes.LexicalWritableScope)1 TransientReceiver (org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1