use of org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl in project kotlin by JetBrains.
the class SamAdapterOverridabilityCondition method getOriginalOfSamAdapterFunction.
// if function is or overrides declaration, returns null; otherwise, return original of sam adapter with substituted type parameters
@Nullable
private static SimpleFunctionDescriptor getOriginalOfSamAdapterFunction(@NotNull SimpleFunctionDescriptor callable) {
if (callable.getDispatchReceiverParameter() != null)
return null;
DeclarationDescriptor containingDeclaration = callable.getContainingDeclaration();
if (!(containingDeclaration instanceof ClassDescriptor)) {
return null;
}
SamAdapterInfo declarationOrSynthesized = getNearestDeclarationOrSynthesized(callable, ((ClassDescriptor) containingDeclaration).getDefaultType());
if (declarationOrSynthesized == null) {
return null;
}
SimpleFunctionDescriptorImpl fun = (SimpleFunctionDescriptorImpl) declarationOrSynthesized.samAdapter.getOriginal();
if (!(fun instanceof SamAdapterFunctionDescriptor)) {
return null;
}
SimpleFunctionDescriptor originalDeclarationOfSam = ((SamAdapterFunctionDescriptor) fun).getBaseDescriptorForSynthetic();
return ((SimpleFunctionDescriptor) originalDeclarationOfSam.substitute(TypeSubstitutor.create(declarationOrSynthesized.ownerType)));
}
use of org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl in project kotlin by JetBrains.
the class SamWrapperCodegen method generateMethod.
private void generateMethod(Type ownerType, Type functionType, ClassBuilder cv, SimpleFunctionDescriptor erasedInterfaceFunction, KotlinType functionJetType) {
// using root context to avoid creating ClassDescriptor and everything else
FunctionCodegen codegen = new FunctionCodegen(state.getRootContext().intoClass((ClassDescriptor) erasedInterfaceFunction.getContainingDeclaration(), OwnerKind.IMPLEMENTATION, state), cv, state, parentCodegen);
FunctionDescriptor invokeFunction = functionJetType.getMemberScope().getContributedFunctions(OperatorNameConventions.INVOKE, NoLookupLocation.FROM_BACKEND).iterator().next().getOriginal();
StackValue functionField = StackValue.field(functionType, ownerType, FUNCTION_FIELD_NAME, false, StackValue.none());
codegen.genSamDelegate(erasedInterfaceFunction, invokeFunction, functionField);
// generate sam bridges
// TODO: erasedInterfaceFunction is actually not an interface function, but function in generated class
SimpleFunctionDescriptor originalInterfaceErased = samType.getAbstractMethod().getOriginal();
SimpleFunctionDescriptorImpl descriptorForBridges = SimpleFunctionDescriptorImpl.create(erasedInterfaceFunction.getContainingDeclaration(), erasedInterfaceFunction.getAnnotations(), originalInterfaceErased.getName(), CallableMemberDescriptor.Kind.DECLARATION, erasedInterfaceFunction.getSource());
descriptorForBridges.initialize(null, originalInterfaceErased.getDispatchReceiverParameter(), originalInterfaceErased.getTypeParameters(), originalInterfaceErased.getValueParameters(), originalInterfaceErased.getReturnType(), Modality.OPEN, originalInterfaceErased.getVisibility());
DescriptorUtilsKt.setSingleOverridden(descriptorForBridges, originalInterfaceErased);
codegen.generateBridges(descriptorForBridges);
}
use of org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl in project kotlin by JetBrains.
the class JavaMethodDescriptor method initialize.
@NotNull
@Override
public SimpleFunctionDescriptorImpl initialize(@Nullable KotlinType receiverParameterType, @Nullable ReceiverParameterDescriptor dispatchReceiverParameter, @NotNull List<? extends TypeParameterDescriptor> typeParameters, @NotNull List<ValueParameterDescriptor> unsubstitutedValueParameters, @Nullable KotlinType unsubstitutedReturnType, @Nullable Modality modality, @NotNull Visibility visibility) {
SimpleFunctionDescriptorImpl descriptor = super.initialize(receiverParameterType, dispatchReceiverParameter, typeParameters, unsubstitutedValueParameters, unsubstitutedReturnType, modality, visibility);
setOperator(OperatorChecks.INSTANCE.check(descriptor).isSuccess());
return descriptor;
}
use of org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl in project kotlin by JetBrains.
the class ControlStructureTypingUtils method createFunctionDescriptorForSpecialConstruction.
private SimpleFunctionDescriptorImpl createFunctionDescriptorForSpecialConstruction(@NotNull ResolveConstruct construct, @NotNull List<String> argumentNames, @NotNull List<Boolean> isArgumentNullable) {
assert argumentNames.size() == isArgumentNullable.size();
SimpleFunctionDescriptorImpl function = SimpleFunctionDescriptorImpl.create(moduleDescriptor, Annotations.Companion.getEMPTY(), construct.getSpecialFunctionName(), CallableMemberDescriptor.Kind.DECLARATION, SourceElement.NO_SOURCE);
TypeParameterDescriptor typeParameter = TypeParameterDescriptorImpl.createWithDefaultBound(function, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT, construct.getSpecialTypeParameterName(), 0);
KotlinType type = typeParameter.getDefaultType();
KotlinType nullableType = TypeUtils.makeNullable(type);
List<ValueParameterDescriptor> valueParameters = new ArrayList<ValueParameterDescriptor>(argumentNames.size());
for (int i = 0; i < argumentNames.size(); i++) {
KotlinType argumentType = isArgumentNullable.get(i) ? nullableType : type;
ValueParameterDescriptorImpl valueParameter = new ValueParameterDescriptorImpl(function, null, i, Annotations.Companion.getEMPTY(), Name.identifier(argumentNames.get(i)), argumentType, /* declaresDefaultValue = */
false, /* isCrossinline = */
false, /* isNoinline = */
false, null, SourceElement.NO_SOURCE);
valueParameters.add(valueParameter);
}
KotlinType returnType = construct != ResolveConstruct.ELVIS ? type : TypeUtilsKt.replaceAnnotations(type, AnnotationsForResolveKt.getExactInAnnotations());
function.initialize(null, null, Lists.newArrayList(typeParameter), valueParameters, returnType, Modality.FINAL, Visibilities.PUBLIC);
return function;
}
use of org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl in project kotlin by JetBrains.
the class ControlStructureTypingUtils method resolveSpecialConstructionAsCall.
/*package*/
ResolvedCall<FunctionDescriptor> resolveSpecialConstructionAsCall(@NotNull Call call, @NotNull ResolveConstruct construct, @NotNull List<String> argumentNames, @NotNull List<Boolean> isArgumentNullable, @NotNull ExpressionTypingContext context, @Nullable MutableDataFlowInfoForArguments dataFlowInfoForArguments) {
SimpleFunctionDescriptorImpl function = createFunctionDescriptorForSpecialConstruction(construct, argumentNames, isArgumentNullable);
TracingStrategy tracing = createTracingForSpecialConstruction(call, construct.getName(), context);
TypeSubstitutor knownTypeParameterSubstitutor = createKnownTypeParameterSubstitutorForSpecialCall(construct, function, context.expectedType);
ResolutionCandidate<FunctionDescriptor> resolutionCandidate = ResolutionCandidate.<FunctionDescriptor>create(call, function, knownTypeParameterSubstitutor);
OverloadResolutionResults<FunctionDescriptor> results = callResolver.resolveCallWithKnownCandidate(call, tracing, context, resolutionCandidate, dataFlowInfoForArguments);
assert results.isSingleResult() : "Not single result after resolving one known candidate";
return results.getResultingCall();
}
Aggregations