Minor. Reformat
This commit is contained in:
+14
-8
@@ -78,20 +78,26 @@ abstract class DataClassMethodGenerator(protected val declaration: KtClassOrObje
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDataClassToStringIfNeeded(properties: List<PropertyDescriptor>) {
|
private fun generateDataClassToStringIfNeeded(properties: List<PropertyDescriptor>) {
|
||||||
val function = getMemberToGenerate(classDescriptor, "toString",
|
val function = getMemberToGenerate(
|
||||||
KotlinBuiltIns::isString, List<ValueParameterDescriptor>::isEmpty) ?: return
|
classDescriptor, "toString",
|
||||||
|
KotlinBuiltIns::isString, List<ValueParameterDescriptor>::isEmpty
|
||||||
|
) ?: return
|
||||||
generateToStringMethod(function, properties)
|
generateToStringMethod(function, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDataClassHashCodeIfNeeded(properties: List<PropertyDescriptor>) {
|
private fun generateDataClassHashCodeIfNeeded(properties: List<PropertyDescriptor>) {
|
||||||
val function = getMemberToGenerate(classDescriptor, "hashCode",
|
val function = getMemberToGenerate(
|
||||||
KotlinBuiltIns::isInt, List<ValueParameterDescriptor>::isEmpty) ?: return
|
classDescriptor, "hashCode",
|
||||||
|
KotlinBuiltIns::isInt, List<ValueParameterDescriptor>::isEmpty
|
||||||
|
) ?: return
|
||||||
generateHashCodeMethod(function, properties)
|
generateHashCodeMethod(function, properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateDataClassEqualsIfNeeded(properties: List<PropertyDescriptor>) {
|
private fun generateDataClassEqualsIfNeeded(properties: List<PropertyDescriptor>) {
|
||||||
val function = getMemberToGenerate(classDescriptor, "equals",
|
val function = getMemberToGenerate(
|
||||||
KotlinBuiltIns::isBoolean) { parameters ->
|
classDescriptor, "equals",
|
||||||
|
KotlinBuiltIns::isBoolean
|
||||||
|
) { parameters ->
|
||||||
parameters.size == 1 && KotlinBuiltIns.isNullableAny(parameters.first().type)
|
parameters.size == 1 && KotlinBuiltIns.isNullableAny(parameters.first().type)
|
||||||
} ?: return
|
} ?: return
|
||||||
generateEqualsMethod(function, properties)
|
generateEqualsMethod(function, properties)
|
||||||
@@ -99,8 +105,8 @@ abstract class DataClassMethodGenerator(protected val declaration: KtClassOrObje
|
|||||||
|
|
||||||
private val dataProperties: List<PropertyDescriptor>
|
private val dataProperties: List<PropertyDescriptor>
|
||||||
get() = primaryConstructorParameters
|
get() = primaryConstructorParameters
|
||||||
.filter { it.hasValOrVar() }
|
.filter { it.hasValOrVar() }
|
||||||
.map { bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, it)!! }
|
.map { bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, it)!! }
|
||||||
|
|
||||||
private val primaryConstructorParameters: List<KtParameter>
|
private val primaryConstructorParameters: List<KtParameter>
|
||||||
get() = (declaration as? KtClass)?.primaryConstructorParameters.orEmpty()
|
get() = (declaration as? KtClass)?.primaryConstructorParameters.orEmpty()
|
||||||
|
|||||||
+7
-2
@@ -19,17 +19,22 @@ package org.jetbrains.kotlin.backend.jvm.intrinsics
|
|||||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
import org.jetbrains.kotlin.backend.jvm.codegen.BlockInfo
|
||||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||||
|
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||||
import org.jetbrains.kotlin.codegen.StackValue
|
import org.jetbrains.kotlin.codegen.StackValue
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
object ArrayConstructor : IntrinsicMethod() {
|
object ArrayConstructor : IntrinsicMethod() {
|
||||||
override fun toCallable(expression: IrMemberAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction {
|
override fun toCallable(
|
||||||
|
expression: IrMemberAccessExpression,
|
||||||
|
signature: JvmMethodSignature,
|
||||||
|
context: JvmBackendContext
|
||||||
|
): IrIntrinsicFunction {
|
||||||
return object : IrIntrinsicFunction(expression, signature, context, expression.argTypes(context)) {
|
return object : IrIntrinsicFunction(expression, signature, context, expression.argTypes(context)) {
|
||||||
|
|
||||||
override fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue =
|
override fun invoke(v: InstructionAdapter, codegen: ExpressionCodegen, data: BlockInfo): StackValue =
|
||||||
codegen.generateCall(expression, this, data)
|
codegen.generateCall(expression, this, data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-13
@@ -24,35 +24,37 @@ import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
fun FunctionDescriptor.toStatic(
|
fun FunctionDescriptor.toStatic(
|
||||||
newOwner: ClassOrPackageFragmentDescriptor,
|
newOwner: ClassOrPackageFragmentDescriptor,
|
||||||
name: Name = this.name,
|
name: Name = this.name,
|
||||||
dispatchReceiverClass: ClassDescriptor? = this.containingDeclaration as? ClassDescriptor
|
dispatchReceiverClass: ClassDescriptor? = this.containingDeclaration as? ClassDescriptor
|
||||||
): FunctionDescriptor {
|
): FunctionDescriptor {
|
||||||
val newFunction = SimpleFunctionDescriptorImpl.create(
|
val newFunction = SimpleFunctionDescriptorImpl.create(
|
||||||
newOwner, AnnotationsImpl(emptyList()),
|
newOwner, AnnotationsImpl(emptyList()),
|
||||||
name,
|
name,
|
||||||
CallableMemberDescriptor.Kind.DECLARATION, this.source
|
CallableMemberDescriptor.Kind.DECLARATION, this.source
|
||||||
)
|
)
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
val dispatchReceiver = dispatchReceiverParameter?.let {
|
val dispatchReceiver = dispatchReceiverParameter?.let {
|
||||||
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
||||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"),
|
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"),
|
||||||
dispatchReceiverClass!!.defaultType, false, false, false, null, dispatchReceiverClass.source, null)
|
dispatchReceiverClass!!.defaultType, false, false, false, null, dispatchReceiverClass.source, null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val extensionReceiver = extensionReceiverParameter?.let {
|
val extensionReceiver = extensionReceiverParameter?.let {
|
||||||
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
||||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"),
|
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"),
|
||||||
it.value.type, false, false, false, null, it.source, null)
|
it.value.type, false, false, false, null, it.source, null
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val valueParameters = listOfNotNull(dispatchReceiver, extensionReceiver) +
|
val valueParameters = listOfNotNull(dispatchReceiver, extensionReceiver) +
|
||||||
valueParameters.map { it.copy(newFunction, it.name, it.index + offset) }
|
valueParameters.map { it.copy(newFunction, it.name, it.index + offset) }
|
||||||
|
|
||||||
newFunction.initialize(
|
newFunction.initialize(
|
||||||
null, null, emptyList()/*TODO: type parameters*/,
|
null, null, emptyList()/*TODO: type parameters*/,
|
||||||
valueParameters, returnType, Modality.FINAL, Visibilities.PUBLIC
|
valueParameters, returnType, Modality.FINAL, Visibilities.PUBLIC
|
||||||
)
|
)
|
||||||
return newFunction
|
return newFunction
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user