use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature in project kotlin by JetBrains.
the class KotlinTypeMapper method mapSignatureWithCustomParameters.
@NotNull
public JvmMethodGenericSignature mapSignatureWithCustomParameters(@NotNull FunctionDescriptor f, @NotNull OwnerKind kind, @NotNull List<ValueParameterDescriptor> valueParameters, boolean skipGenericSignature) {
checkOwnerCompatibility(f);
JvmSignatureWriter sw = skipGenericSignature || f instanceof AccessorForCallableDescriptor ? new JvmSignatureWriter() : new BothSignatureWriter(BothSignatureWriter.Mode.METHOD);
if (f instanceof ClassConstructorDescriptor) {
sw.writeParametersStart();
writeAdditionalConstructorParameters((ClassConstructorDescriptor) f, sw);
for (ValueParameterDescriptor parameter : valueParameters) {
writeParameter(sw, parameter.getType(), f);
}
if (f instanceof AccessorForConstructorDescriptor) {
writeParameter(sw, JvmMethodParameterKind.CONSTRUCTOR_MARKER, DEFAULT_CONSTRUCTOR_MARKER);
}
writeVoidReturn(sw);
} else {
CallableMemberDescriptor directMember = DescriptorUtils.getDirectMember(f);
KotlinType thisIfNeeded = null;
if (OwnerKind.DEFAULT_IMPLS == kind) {
ReceiverTypeAndTypeParameters receiverTypeAndTypeParameters = TypeMapperUtilsKt.patchTypeParametersForDefaultImplMethod(directMember);
writeFormalTypeParameters(CollectionsKt.plus(receiverTypeAndTypeParameters.getTypeParameters(), directMember.getTypeParameters()), sw);
thisIfNeeded = receiverTypeAndTypeParameters.getReceiverType();
} else {
writeFormalTypeParameters(directMember.getTypeParameters(), sw);
if (isAccessor(f) && f.getDispatchReceiverParameter() != null) {
thisIfNeeded = ((ClassDescriptor) f.getContainingDeclaration()).getDefaultType();
}
}
sw.writeParametersStart();
if (thisIfNeeded != null) {
writeParameter(sw, JvmMethodParameterKind.THIS, thisIfNeeded, f);
}
ReceiverParameterDescriptor receiverParameter = f.getExtensionReceiverParameter();
if (receiverParameter != null) {
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.getType(), f);
}
for (ValueParameterDescriptor parameter : valueParameters) {
boolean forceBoxing = MethodSignatureMappingKt.forceSingleValueParameterBoxing(f);
writeParameter(sw, forceBoxing ? TypeUtils.makeNullable(parameter.getType()) : parameter.getType(), f);
}
sw.writeReturnType();
mapReturnType(f, sw);
sw.writeReturnTypeEnd();
}
JvmMethodGenericSignature signature = sw.makeJvmMethodSignature(mapFunctionName(f));
if (kind != OwnerKind.DEFAULT_IMPLS) {
SpecialSignatureInfo specialSignatureInfo = BuiltinMethodsWithSpecialGenericSignature.getSpecialSignatureInfo(f);
if (specialSignatureInfo != null) {
String newGenericSignature = CodegenUtilKt.replaceValueParametersIn(specialSignatureInfo, signature.getGenericsSignature());
return new JvmMethodGenericSignature(signature.getAsmMethod(), signature.getValueParameters(), newGenericSignature);
}
}
return signature;
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature in project kotlin by JetBrains.
the class FunctionCodegen method generateMethod.
public void generateMethod(@NotNull JvmDeclarationOrigin origin, @NotNull FunctionDescriptor functionDescriptor, @NotNull MethodContext methodContext, @NotNull FunctionGenerationStrategy strategy) {
OwnerKind contextKind = methodContext.getContextKind();
if (isInterface(functionDescriptor.getContainingDeclaration()) && functionDescriptor.getVisibility() == Visibilities.PRIVATE && !processInterfaceMember(functionDescriptor, contextKind, state)) {
return;
}
JvmMethodGenericSignature jvmSignature = typeMapper.mapSignatureWithGeneric(functionDescriptor, contextKind);
Method asmMethod = jvmSignature.getAsmMethod();
int flags = getMethodAsmFlags(functionDescriptor, contextKind, state);
if (origin.getOriginKind() == JvmDeclarationOriginKind.SAM_DELEGATION) {
flags |= ACC_SYNTHETIC;
}
if (functionDescriptor.isExternal() && owner instanceof MultifileClassFacadeContext) {
// Native methods are only defined in facades and do not need package part implementations
return;
}
MethodVisitor mv = v.newMethod(origin, flags, asmMethod.getName(), asmMethod.getDescriptor(), jvmSignature.getGenericsSignature(), getThrownExceptions(functionDescriptor, typeMapper));
if (CodegenContextUtil.isImplClassOwner(owner)) {
v.getSerializationBindings().put(METHOD_FOR_FUNCTION, CodegenUtilKt.<FunctionDescriptor>unwrapFrontendVersion(functionDescriptor), asmMethod);
}
generateMethodAnnotations(functionDescriptor, asmMethod, mv);
JvmMethodSignature signature = typeMapper.mapSignatureSkipGeneric(functionDescriptor);
generateParameterAnnotations(functionDescriptor, mv, signature);
GenerateJava8ParameterNamesKt.generateParameterNames(functionDescriptor, mv, signature, state, (flags & ACC_SYNTHETIC) != 0);
generateBridges(functionDescriptor);
if (isJvm8InterfaceWithDefaultsMember(functionDescriptor, state) && contextKind != OwnerKind.DEFAULT_IMPLS && state.getGenerateDefaultImplsForJvm8()) {
generateDelegateForDefaultImpl(functionDescriptor, origin.getElement());
}
boolean staticInCompanionObject = CodegenUtilKt.isJvmStaticInCompanionObject(functionDescriptor);
if (staticInCompanionObject) {
ImplementationBodyCodegen parentBodyCodegen = (ImplementationBodyCodegen) memberCodegen.getParentCodegen();
parentBodyCodegen.addAdditionalTask(new JvmStaticInCompanionObjectGenerator(functionDescriptor, origin, state, parentBodyCodegen));
}
if (!state.getClassBuilderMode().generateBodies || isAbstractMethod(functionDescriptor, contextKind, state)) {
generateLocalVariableTable(mv, jvmSignature, functionDescriptor, getThisTypeForFunction(functionDescriptor, methodContext, typeMapper), new Label(), new Label(), contextKind, typeMapper, 0);
mv.visitEnd();
return;
}
if (!functionDescriptor.isExternal()) {
generateMethodBody(mv, functionDescriptor, methodContext, jvmSignature, strategy, memberCodegen);
} else if (staticInCompanionObject) {
// native @JvmStatic foo() in companion object should delegate to the static native function moved to the outer class
mv.visitCode();
FunctionDescriptor staticFunctionDescriptor = JvmStaticInCompanionObjectGenerator.createStaticFunctionDescriptor(functionDescriptor);
Method accessorMethod = typeMapper.mapAsmMethod(memberCodegen.getContext().accessibleDescriptor(staticFunctionDescriptor, null));
Type owningType = typeMapper.mapClass((ClassifierDescriptor) staticFunctionDescriptor.getContainingDeclaration());
generateDelegateToStaticMethodBody(false, mv, accessorMethod, owningType.getInternalName());
}
endVisit(mv, null, origin.getElement());
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature in project kotlin by JetBrains.
the class JvmSignatureWriter method makeJvmMethodSignature.
@NotNull
public JvmMethodGenericSignature makeJvmMethodSignature(@NotNull String name) {
List<Type> types = new ArrayList<Type>(kotlinParameterTypes.size());
for (JvmMethodParameterSignature parameter : kotlinParameterTypes) {
types.add(parameter.getAsmType());
}
Method asmMethod = new Method(name, jvmReturnType, types.toArray(new Type[types.size()]));
return new JvmMethodGenericSignature(asmMethod, kotlinParameterTypes, makeJavaGenericSignature());
}
use of org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature in project kotlin by JetBrains.
the class PropertyCodegen method generateConstructorPropertyAsMethodForAnnotationClass.
public void generateConstructorPropertyAsMethodForAnnotationClass(KtParameter p, PropertyDescriptor descriptor) {
JvmMethodGenericSignature signature = typeMapper.mapAnnotationParameterSignature(descriptor);
String name = p.getName();
if (name == null)
return;
MethodVisitor mv = v.newMethod(JvmDeclarationOriginKt.OtherOrigin(p, descriptor), ACC_PUBLIC | ACC_ABSTRACT, name, signature.getAsmMethod().getDescriptor(), signature.getGenericsSignature(), null);
KtExpression defaultValue = p.getDefaultValue();
if (defaultValue != null) {
ConstantValue<?> constant = ExpressionCodegen.getCompileTimeConstant(defaultValue, bindingContext, true, state.getShouldInlineConstVals());
assert !state.getClassBuilderMode().generateBodies || constant != null : "Default value for annotation parameter should be compile time value: " + defaultValue.getText();
if (constant != null) {
AnnotationCodegen annotationCodegen = AnnotationCodegen.forAnnotationDefaultValue(mv, memberCodegen, typeMapper);
annotationCodegen.generateAnnotationDefaultValue(constant, descriptor.getType());
}
}
mv.visitEnd();
}
Aggregations