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);
}
}
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);
}
Aggregations