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>) {
|
||||
val function = getMemberToGenerate(classDescriptor, "toString",
|
||||
KotlinBuiltIns::isString, List<ValueParameterDescriptor>::isEmpty) ?: return
|
||||
val function = getMemberToGenerate(
|
||||
classDescriptor, "toString",
|
||||
KotlinBuiltIns::isString, List<ValueParameterDescriptor>::isEmpty
|
||||
) ?: return
|
||||
generateToStringMethod(function, properties)
|
||||
}
|
||||
|
||||
private fun generateDataClassHashCodeIfNeeded(properties: List<PropertyDescriptor>) {
|
||||
val function = getMemberToGenerate(classDescriptor, "hashCode",
|
||||
KotlinBuiltIns::isInt, List<ValueParameterDescriptor>::isEmpty) ?: return
|
||||
val function = getMemberToGenerate(
|
||||
classDescriptor, "hashCode",
|
||||
KotlinBuiltIns::isInt, List<ValueParameterDescriptor>::isEmpty
|
||||
) ?: return
|
||||
generateHashCodeMethod(function, properties)
|
||||
}
|
||||
|
||||
private fun generateDataClassEqualsIfNeeded(properties: List<PropertyDescriptor>) {
|
||||
val function = getMemberToGenerate(classDescriptor, "equals",
|
||||
KotlinBuiltIns::isBoolean) { parameters ->
|
||||
val function = getMemberToGenerate(
|
||||
classDescriptor, "equals",
|
||||
KotlinBuiltIns::isBoolean
|
||||
) { parameters ->
|
||||
parameters.size == 1 && KotlinBuiltIns.isNullableAny(parameters.first().type)
|
||||
} ?: return
|
||||
generateEqualsMethod(function, properties)
|
||||
@@ -99,8 +105,8 @@ abstract class DataClassMethodGenerator(protected val declaration: KtClassOrObje
|
||||
|
||||
private val dataProperties: List<PropertyDescriptor>
|
||||
get() = primaryConstructorParameters
|
||||
.filter { it.hasValOrVar() }
|
||||
.map { bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, it)!! }
|
||||
.filter { it.hasValOrVar() }
|
||||
.map { bindingContext.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, it)!! }
|
||||
|
||||
private val primaryConstructorParameters: List<KtParameter>
|
||||
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.codegen.BlockInfo
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.ExpressionCodegen
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.StackValue
|
||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
|
||||
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||
|
||||
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)) {
|
||||
|
||||
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
|
||||
|
||||
fun FunctionDescriptor.toStatic(
|
||||
newOwner: ClassOrPackageFragmentDescriptor,
|
||||
name: Name = this.name,
|
||||
dispatchReceiverClass: ClassDescriptor? = this.containingDeclaration as? ClassDescriptor
|
||||
newOwner: ClassOrPackageFragmentDescriptor,
|
||||
name: Name = this.name,
|
||||
dispatchReceiverClass: ClassDescriptor? = this.containingDeclaration as? ClassDescriptor
|
||||
): FunctionDescriptor {
|
||||
val newFunction = SimpleFunctionDescriptorImpl.create(
|
||||
newOwner, AnnotationsImpl(emptyList()),
|
||||
name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION, this.source
|
||||
newOwner, AnnotationsImpl(emptyList()),
|
||||
name,
|
||||
CallableMemberDescriptor.Kind.DECLARATION, this.source
|
||||
)
|
||||
|
||||
var offset = 0
|
||||
val dispatchReceiver = dispatchReceiverParameter?.let {
|
||||
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"),
|
||||
dispatchReceiverClass!!.defaultType, false, false, false, null, dispatchReceiverClass.source, null)
|
||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("this"),
|
||||
dispatchReceiverClass!!.defaultType, false, false, false, null, dispatchReceiverClass.source, null
|
||||
)
|
||||
}
|
||||
|
||||
val extensionReceiver = extensionReceiverParameter?.let {
|
||||
ValueParameterDescriptorImpl.createWithDestructuringDeclarations(
|
||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"),
|
||||
it.value.type, false, false, false, null, it.source, null)
|
||||
newFunction, null, offset++, AnnotationsImpl(emptyList()), Name.identifier("receiver"),
|
||||
it.value.type, false, false, false, null, it.source, null
|
||||
)
|
||||
}
|
||||
|
||||
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(
|
||||
null, null, emptyList()/*TODO: type parameters*/,
|
||||
valueParameters, returnType, Modality.FINAL, Visibilities.PUBLIC
|
||||
null, null, emptyList()/*TODO: type parameters*/,
|
||||
valueParameters, returnType, Modality.FINAL, Visibilities.PUBLIC
|
||||
)
|
||||
return newFunction
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user