Minor, extract method JetTypeMapper#writeParameter
This commit is contained in:
@@ -585,7 +585,11 @@ public class JetTypeMapper {
|
|||||||
|
|
||||||
sw.writeParametersStart();
|
sw.writeParametersStart();
|
||||||
writeThisIfNeeded(f, kind, sw);
|
writeThisIfNeeded(f, kind, sw);
|
||||||
writeReceiverIfNeeded(f.getReceiverParameter(), sw);
|
|
||||||
|
ReceiverParameterDescriptor receiverParameter = f.getReceiverParameter();
|
||||||
|
if (receiverParameter != null) {
|
||||||
|
writeParameter(sw, JvmMethodParameterKind.RECEIVER, receiverParameter.getType());
|
||||||
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor parameter : f.getValueParameters()) {
|
for (ValueParameterDescriptor parameter : f.getValueParameters()) {
|
||||||
writeParameter(sw, parameter.getType());
|
writeParameter(sw, parameter.getType());
|
||||||
@@ -655,21 +659,17 @@ public class JetTypeMapper {
|
|||||||
@NotNull OwnerKind kind,
|
@NotNull OwnerKind kind,
|
||||||
@NotNull BothSignatureWriter sw
|
@NotNull BothSignatureWriter sw
|
||||||
) {
|
) {
|
||||||
|
Type thisType;
|
||||||
if (kind == OwnerKind.TRAIT_IMPL) {
|
if (kind == OwnerKind.TRAIT_IMPL) {
|
||||||
ClassDescriptor containingDeclaration = (ClassDescriptor) descriptor.getContainingDeclaration();
|
thisType = getTraitImplThisParameterType((ClassDescriptor) descriptor.getContainingDeclaration(), this);
|
||||||
Type type = getTraitImplThisParameterType(containingDeclaration, this);
|
|
||||||
|
|
||||||
sw.writeParameterType(JvmMethodParameterKind.THIS);
|
|
||||||
sw.writeAsmType(type);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
else if (isAccessor(descriptor) && descriptor.getExpectedThisObject() != null) {
|
else if (isAccessor(descriptor) && descriptor.getExpectedThisObject() != null) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.THIS);
|
thisType = mapClass((ClassifierDescriptor) descriptor.getContainingDeclaration());
|
||||||
mapType(((ClassifierDescriptor) descriptor.getContainingDeclaration()).getDefaultType(), sw, JetTypeMapperMode.VALUE);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
}
|
else return;
|
||||||
|
|
||||||
|
writeParameter(sw, JvmMethodParameterKind.THIS, thisType);
|
||||||
|
}
|
||||||
|
|
||||||
public void writeFormalTypeParameters(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull BothSignatureWriter sw) {
|
public void writeFormalTypeParameters(@NotNull List<TypeParameterDescriptor> typeParameters, @NotNull BothSignatureWriter sw) {
|
||||||
for (TypeParameterDescriptor typeParameter : typeParameters) {
|
for (TypeParameterDescriptor typeParameter : typeParameters) {
|
||||||
@@ -725,45 +725,39 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeReceiverIfNeeded(@Nullable ReceiverParameterDescriptor receiver, @NotNull BothSignatureWriter sw) {
|
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JetType type) {
|
||||||
if (receiver != null) {
|
writeParameter(sw, JvmMethodParameterKind.VALUE, type);
|
||||||
sw.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
|
||||||
mapType(receiver.getType(), sw, JetTypeMapperMode.VALUE);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JetType type) {
|
private void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JvmMethodParameterKind kind, @NotNull JetType type) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.VALUE);
|
sw.writeParameterType(kind);
|
||||||
mapType(type, sw, JetTypeMapperMode.VALUE);
|
mapType(type, sw, JetTypeMapperMode.VALUE);
|
||||||
sw.writeParameterTypeEnd();
|
sw.writeParameterTypeEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void writeParameter(@NotNull BothSignatureWriter sw, @NotNull JvmMethodParameterKind kind, @NotNull Type type) {
|
||||||
|
sw.writeParameterType(kind);
|
||||||
|
sw.writeAsmType(type);
|
||||||
|
sw.writeParameterTypeEnd();
|
||||||
|
}
|
||||||
|
|
||||||
private void writeAdditionalConstructorParameters(@NotNull ConstructorDescriptor descriptor, @NotNull BothSignatureWriter sw) {
|
private void writeAdditionalConstructorParameters(@NotNull ConstructorDescriptor descriptor, @NotNull BothSignatureWriter sw) {
|
||||||
CalculatedClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
|
CalculatedClosure closure = bindingContext.get(CodegenBinding.CLOSURE, descriptor.getContainingDeclaration());
|
||||||
|
|
||||||
ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure);
|
ClassDescriptor captureThis = getExpectedThisObjectForConstructorCall(descriptor, closure);
|
||||||
if (captureThis != null) {
|
if (captureThis != null) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.OUTER);
|
writeParameter(sw, JvmMethodParameterKind.OUTER, captureThis.getDefaultType());
|
||||||
mapType(captureThis.getDefaultType(), sw, JetTypeMapperMode.VALUE);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType captureReceiverType = closure != null ? closure.getCaptureReceiverType() : null;
|
JetType captureReceiverType = closure != null ? closure.getCaptureReceiverType() : null;
|
||||||
if (captureReceiverType != null) {
|
if (captureReceiverType != null) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.RECEIVER);
|
writeParameter(sw, JvmMethodParameterKind.RECEIVER, captureReceiverType);
|
||||||
mapType(captureReceiverType, sw, JetTypeMapperMode.VALUE);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
ClassDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||||
if (containingDeclaration.getKind() == ClassKind.ENUM_CLASS || containingDeclaration.getKind() == ClassKind.ENUM_ENTRY) {
|
if (containingDeclaration.getKind() == ClassKind.ENUM_CLASS || containingDeclaration.getKind() == ClassKind.ENUM_ENTRY) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.ENUM_NAME);
|
writeParameter(sw, JvmMethodParameterKind.ENUM_NAME, KotlinBuiltIns.getInstance().getStringType());
|
||||||
mapType(KotlinBuiltIns.getInstance().getStringType(), sw, JetTypeMapperMode.VALUE);
|
writeParameter(sw, JvmMethodParameterKind.ENUM_ORDINAL, KotlinBuiltIns.getInstance().getIntType());
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
sw.writeParameterType(JvmMethodParameterKind.ENUM_ORDINAL);
|
|
||||||
mapType(KotlinBuiltIns.getInstance().getIntType(), sw, JetTypeMapperMode.VALUE);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closure == null) return;
|
if (closure == null) return;
|
||||||
@@ -785,18 +779,14 @@ public class JetTypeMapper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (type != null) {
|
if (type != null) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.CAPTURED_LOCAL_VARIABLE);
|
writeParameter(sw, JvmMethodParameterKind.CAPTURED_LOCAL_VARIABLE, type);
|
||||||
sw.writeAsmType(type);
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResolvedCall<ConstructorDescriptor> superCall = closure.getSuperCall();
|
ResolvedCall<ConstructorDescriptor> superCall = closure.getSuperCall();
|
||||||
if (superCall != null && isAnonymousObject(descriptor.getContainingDeclaration())) {
|
if (superCall != null && isAnonymousObject(descriptor.getContainingDeclaration())) {
|
||||||
for (JvmMethodParameterSignature parameter : mapSignature(superCall.getResultingDescriptor()).getValueParameters()) {
|
for (JvmMethodParameterSignature parameter : mapSignature(superCall.getResultingDescriptor()).getValueParameters()) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.SUPER_OF_ANONYMOUS_CALL_PARAM);
|
writeParameter(sw, JvmMethodParameterKind.SUPER_OF_ANONYMOUS_CALL_PARAM, parameter.getAsmType());
|
||||||
sw.writeAsmType(parameter.getAsmType());
|
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -808,11 +798,9 @@ public class JetTypeMapper {
|
|||||||
sw.writeParametersStart();
|
sw.writeParametersStart();
|
||||||
|
|
||||||
for (ScriptDescriptor importedScript : importedScripts) {
|
for (ScriptDescriptor importedScript : importedScripts) {
|
||||||
sw.writeParameterType(JvmMethodParameterKind.VALUE);
|
|
||||||
ClassDescriptor descriptor = bindingContext.get(CLASS_FOR_SCRIPT, importedScript);
|
ClassDescriptor descriptor = bindingContext.get(CLASS_FOR_SCRIPT, importedScript);
|
||||||
assert descriptor != null;
|
assert descriptor != null : "Script not found: " + importedScript;
|
||||||
mapType(descriptor.getDefaultType(), sw, JetTypeMapperMode.VALUE);
|
writeParameter(sw, descriptor.getDefaultType());
|
||||||
sw.writeParameterTypeEnd();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ValueParameterDescriptor valueParameter : script.getScriptCodeDescriptor().getValueParameters()) {
|
for (ValueParameterDescriptor valueParameter : script.getScriptCodeDescriptor().getValueParameters()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user