Search in sources :

Example 1 with FakeCallableDescriptorForObject

use of org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject in project kotlin by JetBrains.

the class TracingStrategyImpl method bindReference.

@Override
public <D extends CallableDescriptor> void bindReference(@NotNull BindingTrace trace, @NotNull ResolvedCall<D> resolvedCall) {
    DeclarationDescriptor descriptor = resolvedCall.getCandidateDescriptor();
    if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
        descriptor = ((VariableAsFunctionResolvedCall) resolvedCall).getVariableCall().getCandidateDescriptor();
    }
    if (descriptor instanceof FakeCallableDescriptorForObject) {
        FakeCallableDescriptorForObject fakeCallableDescriptorForObject = (FakeCallableDescriptorForObject) descriptor;
        descriptor = fakeCallableDescriptorForObject.getReferencedDescriptor();
        if (fakeCallableDescriptorForObject.getClassDescriptor().getCompanionObjectDescriptor() != null) {
            trace.record(SHORT_REFERENCE_TO_COMPANION_OBJECT, reference, fakeCallableDescriptorForObject.getClassDescriptor());
        }
    }
    DeclarationDescriptor storedReference = trace.get(REFERENCE_TARGET, reference);
    if (storedReference == null || !ErrorUtils.isError(descriptor)) {
        trace.record(REFERENCE_TARGET, reference, descriptor);
    }
}
Also used : FakeCallableDescriptorForObject(org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject) VariableAsFunctionResolvedCall(org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall) DeclarationDescriptor(org.jetbrains.kotlin.descriptors.DeclarationDescriptor)

Example 2 with FakeCallableDescriptorForObject

use of org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject in project kotlin by JetBrains.

the class ExpressionCodegen method visitSimpleNameExpression.

@Override
public StackValue visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression, @NotNull StackValue receiver) {
    ResolvedCall<?> resolvedCall = CallUtilKt.getResolvedCall(expression, bindingContext);
    DeclarationDescriptor descriptor;
    if (resolvedCall == null) {
        descriptor = bindingContext.get(REFERENCE_TARGET, expression);
    } else {
        if (resolvedCall instanceof VariableAsFunctionResolvedCall) {
            VariableAsFunctionResolvedCall call = (VariableAsFunctionResolvedCall) resolvedCall;
            resolvedCall = call.getVariableCall();
        }
        descriptor = resolvedCall.getResultingDescriptor();
        //Check early if KCallableNameProperty is applicable to prevent closure generation
        StackValue intrinsicResult = applyIntrinsic(descriptor, KCallableNameProperty.class, resolvedCall, receiver);
        if (intrinsicResult != null)
            return intrinsicResult;
        receiver = StackValue.receiver(resolvedCall, receiver, this, null);
        if (descriptor instanceof FakeCallableDescriptorForObject) {
            descriptor = ((FakeCallableDescriptorForObject) descriptor).getReferencedDescriptor();
        }
    }
    assert descriptor != null : "Couldn't find descriptor for '" + expression.getText() + "'";
    descriptor = descriptor.getOriginal();
    boolean isSyntheticField = descriptor instanceof SyntheticFieldDescriptor;
    if (isSyntheticField) {
        descriptor = ((SyntheticFieldDescriptor) descriptor).getPropertyDescriptor();
    }
    StackValue intrinsicResult = applyIntrinsic(descriptor, IntrinsicPropertyGetter.class, resolvedCall, receiver);
    if (intrinsicResult != null)
        return intrinsicResult;
    if (descriptor instanceof PropertyDescriptor) {
        PropertyDescriptor propertyDescriptor = (PropertyDescriptor) descriptor;
        Collection<ExpressionCodegenExtension> codegenExtensions = ExpressionCodegenExtension.Companion.getInstances(state.getProject());
        if (!codegenExtensions.isEmpty() && resolvedCall != null) {
            ExpressionCodegenExtension.Context context = new ExpressionCodegenExtension.Context(typeMapper, v);
            KotlinType returnType = propertyDescriptor.getReturnType();
            for (ExpressionCodegenExtension extension : codegenExtensions) {
                if (returnType != null) {
                    StackValue value = extension.applyProperty(receiver, resolvedCall, context);
                    if (value != null)
                        return value;
                }
            }
        }
        boolean directToField = isSyntheticField && contextKind() != OwnerKind.DEFAULT_IMPLS;
        ClassDescriptor superCallTarget = resolvedCall == null ? null : getSuperCallTarget(resolvedCall.getCall());
        if (directToField) {
            receiver = StackValue.receiverWithoutReceiverArgument(receiver);
        }
        return intermediateValueForProperty(propertyDescriptor, directToField, directToField, superCallTarget, false, receiver, resolvedCall);
    }
    if (descriptor instanceof TypeAliasDescriptor) {
        ClassDescriptor classDescriptor = ((TypeAliasDescriptor) descriptor).getClassDescriptor();
        if (classDescriptor == null) {
            throw new IllegalStateException("Type alias " + descriptor + " static member refernece should be rejected by type checker, " + "since there is no class corresponding to this type alias.");
        }
        descriptor = classDescriptor;
    }
    if (descriptor instanceof ClassDescriptor) {
        ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
        if (isObject(classDescriptor)) {
            return StackValue.singleton(classDescriptor, typeMapper);
        }
        if (isEnumEntry(classDescriptor)) {
            return StackValue.enumEntry(classDescriptor, typeMapper);
        }
        ClassDescriptor companionObjectDescriptor = classDescriptor.getCompanionObjectDescriptor();
        if (companionObjectDescriptor != null) {
            return StackValue.singleton(companionObjectDescriptor, typeMapper);
        }
        return StackValue.none();
    }
    StackValue localOrCaptured = findLocalOrCapturedValue(descriptor);
    if (localOrCaptured != null) {
        return localOrCaptured;
    }
    throw new UnsupportedOperationException("don't know how to generate reference " + descriptor);
}
Also used : BindingContext(org.jetbrains.kotlin.resolve.BindingContext) SyntheticFieldDescriptor(org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor) FakeCallableDescriptorForObject(org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject) SyntheticJavaPropertyDescriptor(org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor) KotlinType(org.jetbrains.kotlin.types.KotlinType) ExpressionCodegenExtension(org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension)

Aggregations

FakeCallableDescriptorForObject (org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject)2 ExpressionCodegenExtension (org.jetbrains.kotlin.codegen.extensions.ExpressionCodegenExtension)1 DeclarationDescriptor (org.jetbrains.kotlin.descriptors.DeclarationDescriptor)1 SyntheticFieldDescriptor (org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor)1 BindingContext (org.jetbrains.kotlin.resolve.BindingContext)1 VariableAsFunctionResolvedCall (org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall)1 SyntheticJavaPropertyDescriptor (org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor)1 KotlinType (org.jetbrains.kotlin.types.KotlinType)1