From 05e19dc5e74a0ddf4c1eca4e828240c2d5291b46 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Fri, 5 Jul 2024 22:44:23 +0900 Subject: [PATCH 1/9] simplify super method call generation --- ...ackInTimeDebuggableImplementTransformer.kt | 21 ++++++++----------- 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt index 5e8b26fe..f3d17b2e 100644 --- a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt +++ b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt @@ -3,10 +3,10 @@ package com.github.kitakkun.backintime.compiler.backend.transformer.implement import com.github.kitakkun.backintime.compiler.backend.BackInTimePluginContext import com.github.kitakkun.backintime.compiler.backend.utils.irPropertySetterCall import com.github.kitakkun.backintime.compiler.backend.utils.irValueContainerPropertySetterCall +import com.github.kitakkun.backintime.compiler.backend.utils.isBackInTimeDebuggable import com.github.kitakkun.backintime.compiler.backend.utils.isBackInTimeGenerated import com.github.kitakkun.backintime.compiler.consts.BackInTimeConsts import org.jetbrains.kotlin.backend.common.lower.createIrBuilder -import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.builders.IrBuilderWithScope import org.jetbrains.kotlin.ir.builders.declarations.addBackingField @@ -82,7 +82,6 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { val parentClassReceiver = declaration.dispatchReceiverParameter!! val (propertyFqNameParameter, valueParameter) = declaration.valueParameters - val superDeclarationSymbol = declaration.overriddenSymbols.firstOrNull { it.owner.modality == Modality.OPEN } val superClassSymbol = parentClass.superClass?.symbol return irBuiltIns.createIrBuilder(declaration.symbol).irBlockBody { @@ -102,9 +101,9 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { ) }.plus( irElseBranch( - if (superDeclarationSymbol != null && superClassSymbol != null) { + if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { irCall( - callee = superDeclarationSymbol.owner, + callee = declaration, superQualifierSymbol = superClassSymbol, ).apply { dispatchReceiver = irGet(parentClassReceiver) @@ -131,9 +130,8 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { val (propertyFqNameParameter, valueParameter) = declaration.valueParameters val irBuilder = irBuiltIns.createIrBuilder(declaration.symbol) - val superDeclarationSymbol = declaration.overriddenSymbols.firstOrNull { it.owner.modality == Modality.OPEN } val superClassSymbol = parentClass.superClass?.symbol - val parentClassReceiver = declaration.dispatchReceiverParameter + val parentClassReceiver = declaration.dispatchReceiverParameter!! return with(irBuilder) { irExprBody( @@ -153,9 +151,9 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { ) }.plus( irElseBranch( - if (superDeclarationSymbol != null && superClassSymbol != null && parentClassReceiver != null) { + if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { irCall( - callee = superDeclarationSymbol.owner, + callee = declaration, superQualifierSymbol = superClassSymbol, ).apply { dispatchReceiver = irGet(parentClassReceiver) @@ -183,9 +181,8 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { val (propertyFqNameParameter, valueParameter) = declaration.valueParameters val irBuilder = irBuiltIns.createIrBuilder(declaration.symbol) - val superDeclarationSymbol = declaration.overriddenSymbols.firstOrNull { it.owner.modality == Modality.OPEN } val superClassSymbol = parentClass.superClass?.symbol - val parentClassReceiver = declaration.dispatchReceiverParameter + val parentClassReceiver = declaration.dispatchReceiverParameter!! return with(irBuilder) { irExprBody( @@ -205,9 +202,9 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { ) }.plus( irElseBranch( - if (superDeclarationSymbol != null && superClassSymbol != null && parentClassReceiver != null) { + if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { irCall( - callee = superDeclarationSymbol.owner, + callee = declaration, superQualifierSymbol = superClassSymbol, ).apply { dispatchReceiver = irGet(parentClassReceiver) From b335bf9aa83ab2d754a913412cc8cc7db54cb2f8 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:35:28 +0900 Subject: [PATCH 2/9] add classFqName to distinct origins of properties or methods --- ...gableCaptureMethodInvocationTransformer.kt | 6 +- .../capture/CaptureValueChangeTransformer.kt | 7 +- ...ackInTimeDebuggableImplementTransformer.kt | 270 +++++++++++------- .../utils/BackInTimeIrGenerateUtils.kt | 12 +- .../runtime/BackInTimeDebugServiceImpl.kt | 43 ++- .../runtime/BackInTimeDebuggable.kt | 18 +- .../BackInTimeDebuggableInstanceEvent.kt | 6 +- .../runtime/internal/CaptureUtils.kt | 2 + .../runtime/internal/EventReportUtils.kt | 6 +- .../event/BackInTimeDebugServiceEvent.kt | 4 +- .../event/BackInTimeDebuggerEvent.kt | 1 + .../test/basic/MethodGenerationTest.kt | 11 +- .../test/basic/PropertyChangeEventTest.kt | 6 +- .../exception/NoSuchPropertyExceptionTest.kt | 6 +- .../exception/TypeMismatchExceptionTest.kt | 9 +- .../AnnotationConfiguredValueContainerTest.kt | 11 +- .../GradleConfiguredValueContainerTest.kt | 11 +- .../test/specific/InheritanceTest.kt | 42 +-- .../test/specific/PureVarsHolderTest.kt | 133 +++++---- .../test/specific/ScopeFunctionsTest.kt | 6 +- .../SelfSerializableValueHolderTest.kt | 9 +- 21 files changed, 379 insertions(+), 240 deletions(-) diff --git a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/BackInTimeDebuggableCaptureMethodInvocationTransformer.kt b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/BackInTimeDebuggableCaptureMethodInvocationTransformer.kt index eaaffd99..03417e86 100644 --- a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/BackInTimeDebuggableCaptureMethodInvocationTransformer.kt +++ b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/BackInTimeDebuggableCaptureMethodInvocationTransformer.kt @@ -11,6 +11,7 @@ import org.jetbrains.kotlin.ir.builders.irGet import org.jetbrains.kotlin.ir.builders.irString import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.expressions.IrBlockBody +import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable import org.jetbrains.kotlin.ir.util.isPropertyAccessor import org.jetbrains.kotlin.ir.util.parentClassOrNull import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid @@ -32,8 +33,9 @@ class BackInTimeDebuggableCaptureMethodInvocationTransformer : IrElementTransfor val notifyMethodCallFunctionCall = irCall(reportMethodInvocationFunctionSymbol).apply { putValueArgument(0, irGet(parentClassDispatchReceiver)) - putValueArgument(1, irGet(uuidVariable)) - putValueArgument(2, irString(declaration.name.asString())) + putValueArgument(1, irString(parentClass.fqNameWhenAvailable?.asString() ?: return declaration)) + putValueArgument(2, irGet(uuidVariable)) + putValueArgument(3, irString(declaration.name.asString())) } (declaration.body as? IrBlockBody)?.statements?.addAll(0, listOf(uuidVariable, notifyMethodCallFunctionCall)) diff --git a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/CaptureValueChangeTransformer.kt b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/CaptureValueChangeTransformer.kt index 5a7b3433..1da21d51 100644 --- a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/CaptureValueChangeTransformer.kt +++ b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/capture/CaptureValueChangeTransformer.kt @@ -70,9 +70,10 @@ class CaptureValueChangeTransformer( valueArgument = with(irBuiltIns.createIrBuilder(symbol)) { irCall(captureThenReturnValueFunctionSymbol).apply { putValueArgument(0, irGet(classDispatchReceiverParameter)) - putValueArgument(1, irGet(uuidVariable)) - putValueArgument(2, irString(property.fqNameWhenAvailable?.asString() ?: return null)) - putValueArgument(3, value) + putValueArgument(1, irString(parentClassSymbol.owner.fqNameWhenAvailable?.asString() ?: return null)) + putValueArgument(2, irGet(uuidVariable)) + putValueArgument(3, irString(property.name.asString())) + putValueArgument(4, value) } }, ) diff --git a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt index f3d17b2e..6ce95b79 100644 --- a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt +++ b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/transformer/implement/BackInTimeDebuggableImplementTransformer.kt @@ -34,7 +34,6 @@ import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.types.typeOrFail import org.jetbrains.kotlin.ir.types.typeWith import org.jetbrains.kotlin.ir.util.classId -import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable import org.jetbrains.kotlin.ir.util.kotlinFqName import org.jetbrains.kotlin.ir.util.parentAsClass import org.jetbrains.kotlin.ir.util.properties @@ -75,59 +74,96 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { } /** - * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.forceSetValue] + * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.forceSetValue]: + * ```kotlin + * fun forceSetValue(propertyOwnerClassFqName: String, propertyName: String, value: Any?) { + * if (ownerClassFqName == "com.example.MyClass") { + * when (propertyName) { + * "prop1" -> prop1 = value + * "prop2" -> prop3 = value + * ... + * else -> throw NoSuchPropertyException(...) + * } + * } else { + * super.forceSetValue(ownerClassFqName, propertyName, value) + * } + * } + * ``` */ private fun generateForceSetPropertyMethodBody(declaration: IrSimpleFunction): IrBody { val parentClass = declaration.parentAsClass val parentClassReceiver = declaration.dispatchReceiverParameter!! - val (propertyFqNameParameter, valueParameter) = declaration.valueParameters + val (ownerClassFqNameParameter, propertyNameParameter, valueParameter) = declaration.valueParameters val superClassSymbol = parentClass.superClass?.symbol return irBuiltIns.createIrBuilder(declaration.symbol).irBlockBody { - +irWhen( + +irIfThenElse( type = irBuiltIns.unitType, - branches = parentClass.properties.mapNotNull { property -> - irBranch( - condition = irEquals( - arg1 = irGet(propertyFqNameParameter), - arg2 = irString(property.fqNameWhenAvailable?.asString() ?: return@mapNotNull null), - ), - result = irSetPropertyValue( - parentClassReceiver, - property, - valueParameter, - ) ?: return@mapNotNull null, - ) - }.plus( - irElseBranch( - if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { - irCall( - callee = declaration, - superQualifierSymbol = superClassSymbol, - ).apply { - dispatchReceiver = irGet(parentClassReceiver) - putValueArgument(0, irGet(propertyFqNameParameter)) - putValueArgument(1, irGet(valueParameter)) - } - } else { - irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { - putValueArgument(0, irGet(propertyFqNameParameter)) - putValueArgument(1, irString(parentClass.kotlinFqName.asString())) - } - }, - ), - ).toList(), + condition = irEquals(irGet(ownerClassFqNameParameter), irString(parentClass.kotlinFqName.asString())), + thenPart = irWhen( + type = irBuiltIns.unitType, + branches = parentClass.properties + .mapNotNull { property -> + irBranch( + condition = irEquals( + arg1 = irGet(propertyNameParameter), + arg2 = irString(property.name.asString()), + ), + result = irSetPropertyValue( + parentClassReceiver, + property, + valueParameter, + ) ?: return@mapNotNull null, + ) + }.plus( + irElseBranch( + irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { + putValueArgument(0, irGet(propertyNameParameter)) + putValueArgument(1, irString(parentClass.kotlinFqName.asString())) + }, + ), + ).toList(), + ), + elsePart = if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { + irCall( + callee = declaration, + superQualifierSymbol = superClassSymbol, + ).apply { + dispatchReceiver = irGet(parentClassReceiver) + putValueArgument(0, irGet(ownerClassFqNameParameter)) + putValueArgument(1, irGet(propertyNameParameter)) + putValueArgument(2, irGet(valueParameter)) + } + } else { + irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { + putValueArgument(0, irGet(propertyNameParameter)) + putValueArgument(1, irString(parentClass.kotlinFqName.asString())) + } + }, ) } } /** - * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.serializeValue] + * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.serializeValue]: + * ```kotlin + * override fun serializeValue(propertyOwnerClassFqName: String, propertyName: String, value: Any?): String = + * if (ownerClassFqName == "com.example.MyClass") { + * when (propertyName) { + * "prop1" -> backInTimeJson.encodeToString(value) + * "prop2" -> backInTimeJson.encodeToString(value) + * ... + * else -> throw NoSuchPropertyException(...) + * } + * } else { + * super.serializeValue(ownerClassFqName, propertyName, value) + * } + * ``` */ private fun generateSerializePropertyMethodBody(declaration: IrSimpleFunction): IrBody { val parentClass = declaration.parentAsClass - val (propertyFqNameParameter, valueParameter) = declaration.valueParameters + val (ownerClassFqNameParameter, propertyNameParameter, valueParameter) = declaration.valueParameters val irBuilder = irBuiltIns.createIrBuilder(declaration.symbol) val superClassSymbol = parentClass.superClass?.symbol @@ -135,50 +171,73 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { return with(irBuilder) { irExprBody( - irWhen( + irIfThenElse( type = irBuiltIns.stringType, - branches = parentClass.properties.mapNotNull { property -> - irBranch( - condition = irEquals( - arg1 = irGet(propertyFqNameParameter), - arg2 = irString(property.fqNameWhenAvailable?.asString() ?: return@mapNotNull null), - ), - result = irCall(encodeToStringFunction).apply { - extensionReceiver = irCall(backInTimeJsonGetter) - putValueArgument(0, irGet(valueParameter)) - putTypeArgument(index = 0, type = property.getter?.returnType?.getSerializerType() ?: return@mapNotNull null) - }, - ) - }.plus( - irElseBranch( - if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { - irCall( - callee = declaration, - superQualifierSymbol = superClassSymbol, - ).apply { - dispatchReceiver = irGet(parentClassReceiver) - putValueArgument(0, irGet(propertyFqNameParameter)) - putValueArgument(1, irGet(valueParameter)) - } - } else { - irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { - putValueArgument(0, irGet(propertyFqNameParameter)) - putValueArgument(1, irString(parentClass.kotlinFqName.asString())) - } - }, - ), - ).toList(), + condition = irEquals(irGet(ownerClassFqNameParameter), irString(parentClass.kotlinFqName.asString())), + thenPart = irWhen( + type = irBuiltIns.stringType, + branches = parentClass.properties + .mapNotNull { property -> + irBranch( + condition = irEquals( + arg1 = irGet(propertyNameParameter), + arg2 = irString(property.name.asString()), + ), + result = irCall(encodeToStringFunction).apply { + extensionReceiver = irCall(backInTimeJsonGetter) + putValueArgument(0, irGet(valueParameter)) + putTypeArgument(index = 0, type = property.getter?.returnType?.getSerializerType() ?: return@mapNotNull null) + }, + ) + }.plus( + irElseBranch( + irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { + putValueArgument(0, irGet(propertyNameParameter)) + putValueArgument(1, irString(parentClass.kotlinFqName.asString())) + }, + ), + ).toList(), + ), + elsePart = if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { + irCall( + callee = declaration, + superQualifierSymbol = superClassSymbol, + ).apply { + dispatchReceiver = irGet(parentClassReceiver) + putValueArgument(0, irGet(ownerClassFqNameParameter)) + putValueArgument(1, irGet(propertyNameParameter)) + putValueArgument(2, irGet(valueParameter)) + } + } else { + irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { + putValueArgument(0, irGet(propertyNameParameter)) + putValueArgument(1, irString(parentClass.kotlinFqName.asString())) + } + }, ), ) } } /** - * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.deserializeValue] + * generate body for [com.github.kitakkun.backintime.runtime.BackInTimeDebuggable.deserializeValue]: + * ```kotlin + * override fun deserializeValue(propertyOwnerClassFqName: String, propertyName: String, value: Any?): String = + * if (ownerClassFqName == "com.example.MyClass") { + * when (propertyName) { + * "prop1" -> backInTimeJson.decodeFromString(value) + * "prop2" -> backInTimeJson.decodeFromString(value) + * ... + * else -> throw NoSuchPropertyException(...) + * } + * } else { + * super.deserializeValue(ownerClassFqName, propertyName, value) + * } + * ``` */ private fun generateDeserializePropertyMethodBody(declaration: IrSimpleFunction): IrBody { val parentClass = declaration.parentAsClass - val (propertyFqNameParameter, valueParameter) = declaration.valueParameters + val (ownerClassFqNameParameter, propertyNameParameter, valueParameter) = declaration.valueParameters val irBuilder = irBuiltIns.createIrBuilder(declaration.symbol) val superClassSymbol = parentClass.superClass?.symbol @@ -186,39 +245,48 @@ class BackInTimeDebuggableImplementTransformer : IrElementTransformerVoid() { return with(irBuilder) { irExprBody( - irWhen( + irIfThenElse( type = irBuiltIns.anyNType, - branches = parentClass.properties.mapNotNull { property -> - irBranch( - condition = irEquals( - arg1 = irGet(propertyFqNameParameter), - arg2 = irString(property.fqNameWhenAvailable?.asString() ?: return@mapNotNull null), - ), - result = irCall(decodeFromStringFunction).apply { - extensionReceiver = irCall(backInTimeJsonGetter) - putValueArgument(0, irGet(valueParameter)) - putTypeArgument(index = 0, type = property.getter?.returnType?.getSerializerType() ?: return@mapNotNull null) - }, - ) - }.plus( - irElseBranch( - if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { - irCall( - callee = declaration, - superQualifierSymbol = superClassSymbol, - ).apply { - dispatchReceiver = irGet(parentClassReceiver) - putValueArgument(0, irGet(propertyFqNameParameter)) - putValueArgument(1, irGet(valueParameter)) - } - } else { + condition = irEquals(irGet(ownerClassFqNameParameter), irString(parentClass.kotlinFqName.asString())), + thenPart = irWhen( + type = irBuiltIns.anyNType, + branches = parentClass.properties.mapNotNull { property -> + irBranch( + condition = irEquals( + arg1 = irGet(propertyNameParameter), + arg2 = irString(property.name.asString()), + ), + result = irCall(decodeFromStringFunction).apply { + extensionReceiver = irCall(backInTimeJsonGetter) + putValueArgument(0, irGet(valueParameter)) + putTypeArgument(index = 0, type = property.getter?.returnType?.getSerializerType() ?: return@mapNotNull null) + }, + ) + }.plus( + irElseBranch( irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { - putValueArgument(0, irGet(propertyFqNameParameter)) + putValueArgument(0, irGet(propertyNameParameter)) putValueArgument(1, irString(parentClass.kotlinFqName.asString())) - } - }, - ), - ).toList(), + }, + ), + ).toList(), + ), + elsePart = if (superClassSymbol != null && superClassSymbol.owner.isBackInTimeDebuggable) { + irCall( + callee = declaration, + superQualifierSymbol = superClassSymbol, + ).apply { + dispatchReceiver = irGet(parentClassReceiver) + putValueArgument(0, irGet(ownerClassFqNameParameter)) + putValueArgument(1, irGet(propertyNameParameter)) + putValueArgument(2, irGet(valueParameter)) + } + } else { + irCall(throwNoSuchPropertyExceptionFunctionSymbol).apply { + putValueArgument(0, irGet(propertyNameParameter)) + putValueArgument(1, irString(parentClass.kotlinFqName.asString())) + } + }, ), ) } diff --git a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/utils/BackInTimeIrGenerateUtils.kt b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/utils/BackInTimeIrGenerateUtils.kt index 96345457..df062933 100644 --- a/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/utils/BackInTimeIrGenerateUtils.kt +++ b/backintime-plugin/compiler/src/main/kotlin/com/github/kitakkun/backintime/compiler/backend/utils/BackInTimeIrGenerateUtils.kt @@ -13,19 +13,22 @@ import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.types.classOrNull import org.jetbrains.kotlin.ir.util.classId import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable +import org.jetbrains.kotlin.ir.util.parentClassOrNull import org.jetbrains.kotlin.name.SpecialNames context(IrBuilderWithScope, BackInTimePluginContext) fun irCapturePropertyValue( + ownerClassName: String, propertyFqName: String, getValueCall: IrCall, instanceParameter: IrValueParameter, uuidVariable: IrVariable, ) = irCall(reportPropertyValueChangeFunctionSymbol).apply { putValueArgument(0, irGet(instanceParameter)) - putValueArgument(1, irGet(uuidVariable)) - putValueArgument(2, irString(propertyFqName)) - putValueArgument(3, getValueCall) + putValueArgument(1, irString(ownerClassName)) + putValueArgument(2, irGet(uuidVariable)) + putValueArgument(3, irString(propertyFqName)) + putValueArgument(4, getValueCall) } context(IrBuilderWithScope, BackInTimePluginContext) @@ -36,7 +39,8 @@ fun IrProperty.generateCaptureValueCallForValueContainer( val getter = getter ?: return null val valueGetterSymbol = getValueHolderValueGetterSymbol() ?: return null return irCapturePropertyValue( - propertyFqName = fqNameWhenAvailable?.asString() ?: return null, + ownerClassName = parentClassOrNull?.fqNameWhenAvailable?.asString() ?: return null, + propertyFqName = name.asString(), getValueCall = if (valueGetterSymbol == getter.symbol) { irCall(getter.symbol).apply { dispatchReceiver = irGet(instanceParameter) diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt index b44124b9..a74a52e8 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt @@ -103,7 +103,12 @@ class BackInTimeDebugServiceImpl( } is BackInTimeDebuggerEvent.ForceSetPropertyValue -> { - forceSetValue(event.instanceUUID, event.propertyFqName, event.value) + forceSetValue( + instanceId = event.instanceUUID, + propertyOwnerClassName = event.propertyOwnerClassName, + propertyName = event.propertyFqName, + value = event.value, + ) null } @@ -141,14 +146,20 @@ class BackInTimeDebugServiceImpl( methodName = event.methodName, methodCallUUID = event.methodCallId, calledAt = Clock.System.now().epochSeconds, + ownerClassFqName = event.ownerClassFqName, ) private fun notifyPropertyChanged(event: BackInTimeDebuggableInstanceEvent.PropertyValueChange): BackInTimeDebugServiceEvent { try { - val serializedValue = event.instance.serializeValue(event.propertyFqName, event.propertyValue) + val serializedValue = event.instance.serializeValue( + propertyOwnerClassFqName = event.ownerClassFqName, + propertyName = event.propertyName, + value = event.propertyValue, + ) return BackInTimeDebugServiceEvent.NotifyValueChange( instanceUUID = event.instance.backInTimeInstanceUUID, - propertyFqName = event.propertyFqName, + propertyName = event.propertyName, + ownerClassFqName = event.ownerClassFqName, value = serializedValue, methodCallUUID = event.methodCallId, ) @@ -157,11 +168,31 @@ class BackInTimeDebugServiceImpl( } } - private fun forceSetValue(instanceId: String, name: String, value: String) { + /** + * force update the state of a property. This method can be used for back-in-time debugging. + * @param instanceId the identifier for the property owner class + * @param propertyOwnerClassName the full-qualified class name of the property owner class. + * @param propertyName the name of the target property. + * @param value Json-encoded value which will be assigned to the property. + */ + private fun forceSetValue( + instanceId: String, + propertyOwnerClassName: String, + propertyName: String, + value: String, + ) { val targetInstance = instanceManager.getInstanceById(instanceId) ?: return try { - val deserializedValue = targetInstance.deserializeValue(name, value) - targetInstance.forceSetValue(name, deserializedValue) + val deserializedValue = targetInstance.deserializeValue( + propertyOwnerClassFqName = propertyOwnerClassName, + propertyName = propertyName, + value = value, + ) + targetInstance.forceSetValue( + propertyOwnerClassFqName = propertyOwnerClassName, + propertyName = propertyName, + value = deserializedValue, + ) } catch (e: SerializationException) { sendOrQueueEvent(BackInTimeDebugServiceEvent.Error(e.message ?: "Unknown error")) } diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebuggable.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebuggable.kt index 102d254f..ebe9faef 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebuggable.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebuggable.kt @@ -8,11 +8,23 @@ interface BackInTimeDebuggable { val backInTimeInitializedPropertyMap: MutableMap @Throws(BackInTimeRuntimeException.TypeMismatchException::class, BackInTimeRuntimeException.NoSuchPropertyException::class) - fun forceSetValue(propertyName: String, value: Any?) + fun forceSetValue( + propertyOwnerClassFqName: String, + propertyName: String, + value: Any?, + ) @Throws(BackInTimeRuntimeException.NoSuchPropertyException::class, SerializationException::class) - fun serializeValue(propertyName: String, value: Any?): String + fun serializeValue( + propertyOwnerClassFqName: String, + propertyName: String, + value: Any?, + ): String @Throws(BackInTimeRuntimeException.NoSuchPropertyException::class, SerializationException::class) - fun deserializeValue(propertyName: String, value: String): Any? + fun deserializeValue( + propertyOwnerClassFqName: String, + propertyName: String, + value: String, + ): Any? } diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt index 0fd6aaf2..b37fc29c 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt @@ -40,6 +40,7 @@ sealed interface BackInTimeDebuggableInstanceEvent { */ data class MethodCall( val instance: BackInTimeDebuggable, + val ownerClassFqName: String, val methodCallId: String, val methodName: String, ) : BackInTimeDebuggableInstanceEvent @@ -48,13 +49,14 @@ sealed interface BackInTimeDebuggableInstanceEvent { * Notify that a property value is changed * @param instance the reference to the instance * @param methodCallId the unique id of the method call - * @param propertyFqName the fqName of the property. + * @param propertyName the fqName of the property. * @param propertyValue the value of the property */ data class PropertyValueChange( val instance: BackInTimeDebuggable, val methodCallId: String, - val propertyFqName: String, + val ownerClassFqName: String, + val propertyName: String, val propertyValue: Any?, ) : BackInTimeDebuggableInstanceEvent } diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/CaptureUtils.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/CaptureUtils.kt index e8123253..fe529c18 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/CaptureUtils.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/CaptureUtils.kt @@ -7,6 +7,7 @@ import com.github.kitakkun.backintime.runtime.BackInTimeDebuggable @BackInTimeCompilerInternalApi internal fun captureThenReturnValue( instance: BackInTimeDebuggable, + ownerClassFqName: String, methodInvocationId: String, propertyFqName: String, propertyValue: T, @@ -16,6 +17,7 @@ internal fun captureThenReturnValue( methodInvocationId = methodInvocationId, propertyFqName = propertyFqName, propertyValue = propertyValue, + ownerClassFqName = ownerClassFqName, ) return propertyValue } diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/EventReportUtils.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/EventReportUtils.kt index 4a9e594d..c7fc6cd6 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/EventReportUtils.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/internal/EventReportUtils.kt @@ -25,6 +25,7 @@ internal fun reportInstanceRegistration( @BackInTimeCompilerInternalApi internal fun reportMethodInvocation( instance: BackInTimeDebuggable, + ownerClassFqName: String, methodInvocationId: String, methodName: String, ) = getBackInTimeDebugService().processInstanceEvent( @@ -32,12 +33,14 @@ internal fun reportMethodInvocation( instance = instance, methodCallId = methodInvocationId, methodName = methodName, + ownerClassFqName = ownerClassFqName, ), ) @BackInTimeCompilerInternalApi internal fun reportPropertyValueChange( instance: BackInTimeDebuggable, + ownerClassFqName: String, methodInvocationId: String, propertyFqName: String, propertyValue: Any?, @@ -45,8 +48,9 @@ internal fun reportPropertyValueChange( BackInTimeDebuggableInstanceEvent.PropertyValueChange( instance = instance, methodCallId = methodInvocationId, - propertyFqName = propertyFqName, + propertyName = propertyFqName, propertyValue = propertyValue, + ownerClassFqName = ownerClassFqName, ), ) diff --git a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebugServiceEvent.kt b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebugServiceEvent.kt index d446e6b5..505d7605 100644 --- a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebugServiceEvent.kt +++ b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebugServiceEvent.kt @@ -28,7 +28,8 @@ sealed class BackInTimeDebugServiceEvent { @Serializable data class NotifyValueChange( val instanceUUID: String, - val propertyFqName: String, + val ownerClassFqName: String, + val propertyName: String, val value: String, val methodCallUUID: String, ) : BackInTimeDebugServiceEvent() @@ -36,6 +37,7 @@ sealed class BackInTimeDebugServiceEvent { @Serializable data class NotifyMethodCall( val instanceUUID: String, + val ownerClassFqName: String, val methodName: String, val methodCallUUID: String, val calledAt: Long, diff --git a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt index 44a4a9f7..ca519bef 100644 --- a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt +++ b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt @@ -24,6 +24,7 @@ sealed class BackInTimeDebuggerEvent { data class ForceSetPropertyValue( val instanceUUID: String, val propertyFqName: String, + val propertyOwnerClassName: String, val value: String, val valueType: String, ) : BackInTimeDebuggerEvent() diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/MethodGenerationTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/MethodGenerationTest.kt index e6fa2f55..06674de5 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/MethodGenerationTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/MethodGenerationTest.kt @@ -11,7 +11,8 @@ import kotlin.test.assertIs class MethodGenerationTest : BackInTimeDebugServiceTest() { companion object { - private const val PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.basic.MethodGenerationTest.TestStateHolder.property" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.basic.MethodGenerationTest.TestStateHolder" + private const val PROPERTY_NAME = "property" } @BackInTime @@ -24,14 +25,14 @@ class MethodGenerationTest : BackInTimeDebugServiceTest() { val holder = TestStateHolder() assertIs(holder) - assertEquals("10", holder.serializeValue(PROPERTY_FQ_NAME, 10)) - assertEquals(10, holder.deserializeValue(PROPERTY_FQ_NAME, "10")) + assertEquals("10", holder.serializeValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = PROPERTY_NAME, value = 10)) + assertEquals(10, holder.deserializeValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = PROPERTY_NAME, value = "10")) - holder.forceSetValue(PROPERTY_FQ_NAME, 10) + holder.forceSetValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = PROPERTY_NAME, value = 10) assertEquals(10, holder.property) assertFailsWith(BackInTimeRuntimeException.TypeMismatchException::class) { - holder.forceSetValue(PROPERTY_FQ_NAME, "0") + holder.forceSetValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = PROPERTY_NAME, value = "0") } } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/PropertyChangeEventTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/PropertyChangeEventTest.kt index daaf79a4..3d1bd2f7 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/PropertyChangeEventTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/basic/PropertyChangeEventTest.kt @@ -11,7 +11,8 @@ import kotlin.test.assertIs class PropertyChangeEventTest : BackInTimeDebugServiceTest() { companion object { - private const val PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.basic.PropertyChangeEventTest.TestStateHolder.property" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.basic.PropertyChangeEventTest.TestStateHolder" + private const val PROPERTY_NAME = "property" } @BackInTime @@ -31,7 +32,8 @@ class PropertyChangeEventTest : BackInTimeDebugServiceTest() { delay(100) assertEquals(expected = 1, actual = notifyValueChangeEvents.size) assertEquals(holder.backInTimeInstanceUUID, notifyValueChangeEvents[0].instanceUUID) - assertEquals(expected = PROPERTY_FQ_NAME, actual = notifyValueChangeEvents[0].propertyFqName) + assertEquals(expected = CLASS_FQ_NAME, actual = notifyValueChangeEvents[0].ownerClassFqName) + assertEquals(expected = PROPERTY_NAME, actual = notifyValueChangeEvents[0].propertyName) assertEquals(expected = 1, actual = notifyValueChangeEvents[0].value.toInt()) // external access can't be captured diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/NoSuchPropertyExceptionTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/NoSuchPropertyExceptionTest.kt index cda1db81..17f327fb 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/NoSuchPropertyExceptionTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/NoSuchPropertyExceptionTest.kt @@ -18,7 +18,7 @@ class NoSuchPropertyExceptionTest { val holder = TestStateHolder() assertIs(holder) assertFailsWith(BackInTimeRuntimeException.NoSuchPropertyException::class) { - holder.forceSetValue("property2", "test") + holder.forceSetValue("", "property2", "test") } } @@ -27,7 +27,7 @@ class NoSuchPropertyExceptionTest { val holder = TestStateHolder() assertIs(holder) assertFailsWith(BackInTimeRuntimeException.NoSuchPropertyException::class) { - holder.serializeValue("property2", "test") + holder.serializeValue("", "property2", "test") } } @@ -36,7 +36,7 @@ class NoSuchPropertyExceptionTest { val holder = TestStateHolder() assertIs(holder) assertFailsWith(BackInTimeRuntimeException.NoSuchPropertyException::class) { - holder.deserializeValue("property2", "test") + holder.deserializeValue("", "property2", "test") } } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/TypeMismatchExceptionTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/TypeMismatchExceptionTest.kt index 4fcfd8a5..0f4dc718 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/TypeMismatchExceptionTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/exception/TypeMismatchExceptionTest.kt @@ -13,8 +13,9 @@ import kotlin.test.assertIs class TypeMismatchExceptionTest { companion object { - private const val PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.exception.TypeMismatchExceptionTest.TestStateHolder.property" - private const val VALUE_CONTAINER_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.exception.TypeMismatchExceptionTest.TestStateHolder.valueContainerProperty" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.exception.TypeMismatchExceptionTest.TestStateHolder" + private const val PROPERTY_NAME = "property" + private const val VALUE_CONTAINER_PROPERTY_NAME = "valueContainerProperty" } @ValueContainer @@ -33,7 +34,7 @@ class TypeMismatchExceptionTest { val holder = TestStateHolder() assertIs(holder) assertFailsWith(BackInTimeRuntimeException.TypeMismatchException::class) { - holder.forceSetValue(PROPERTY_FQ_NAME, 1) + holder.forceSetValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = PROPERTY_NAME, value = 1) } } @@ -42,7 +43,7 @@ class TypeMismatchExceptionTest { val holder = TestStateHolder() assertIs(holder) assertFailsWith(BackInTimeRuntimeException.TypeMismatchException::class) { - holder.forceSetValue(VALUE_CONTAINER_PROPERTY_FQ_NAME, "test") + holder.forceSetValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = VALUE_CONTAINER_PROPERTY_NAME, value = "test") } } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/AnnotationConfiguredValueContainerTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/AnnotationConfiguredValueContainerTest.kt index e0b3d270..f036fab7 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/AnnotationConfiguredValueContainerTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/AnnotationConfiguredValueContainerTest.kt @@ -15,7 +15,8 @@ import kotlin.test.assertIs class AnnotationConfiguredValueContainerTest : BackInTimeDebugServiceTest() { companion object { - private const val CONTAINER_FQ_NAME = "com.github.kitakkun.backintime.test.specific.AnnotationConfiguredValueContainerTest.ValueContainerHolder.container" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.AnnotationConfiguredValueContainerTest.ValueContainerHolder" + private const val CONTAINER_NAME = "container" } @ValueContainer @@ -48,7 +49,7 @@ class AnnotationConfiguredValueContainerTest : BackInTimeDebugServiceTest() { assertEquals(10, holder.container.value) assertEquals(1, notifyValueChangeEvents.size) assertEquals(holder.backInTimeInstanceUUID, notifyValueChangeEvents[0].instanceUUID) - assertEquals(CONTAINER_FQ_NAME, notifyValueChangeEvents[0].propertyFqName) + assertEquals(CONTAINER_NAME, notifyValueChangeEvents[0].propertyName) assertEquals(10, notifyValueChangeEvents[0].value.toInt()) } @@ -57,8 +58,8 @@ class AnnotationConfiguredValueContainerTest : BackInTimeDebugServiceTest() { val holder = ValueContainerHolder() assertIs(holder) - assertEquals("10", holder.serializeValue(CONTAINER_FQ_NAME, 10)) - assertEquals(10, holder.deserializeValue(CONTAINER_FQ_NAME, "10")) + assertEquals("10", holder.serializeValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = CONTAINER_NAME, value = 10)) + assertEquals(10, holder.deserializeValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = CONTAINER_NAME, value = "10")) } @Test @@ -66,7 +67,7 @@ class AnnotationConfiguredValueContainerTest : BackInTimeDebugServiceTest() { val holder = ValueContainerHolder() assertIs(holder) - holder.forceSetValue(CONTAINER_FQ_NAME, 10) + holder.forceSetValue(propertyOwnerClassFqName = CLASS_FQ_NAME, propertyName = CONTAINER_NAME, value = 10) assertEquals(10, holder.container.value) } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/GradleConfiguredValueContainerTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/GradleConfiguredValueContainerTest.kt index 22a1f68d..bc9af46c 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/GradleConfiguredValueContainerTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/GradleConfiguredValueContainerTest.kt @@ -11,7 +11,8 @@ import kotlin.test.assertIs class GradleConfiguredValueContainerTest : BackInTimeDebugServiceTest() { companion object { - private const val CONTAINER_FQ_NAME = "com.github.kitakkun.backintime.test.specific.GradleConfiguredValueContainerTest.ValueContainerHolder.container" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.GradleConfiguredValueContainerTest.ValueContainerHolder" + private const val CONTAINER_NAME = "container" } /** @@ -57,7 +58,7 @@ class GradleConfiguredValueContainerTest : BackInTimeDebugServiceTest() { assertEquals(10, holder.container.value) assertEquals(1, notifyValueChangeEvents.size) assertEquals(holder.backInTimeInstanceUUID, notifyValueChangeEvents[0].instanceUUID) - assertEquals(CONTAINER_FQ_NAME, notifyValueChangeEvents[0].propertyFqName) + assertEquals(CONTAINER_NAME, notifyValueChangeEvents[0].propertyName) assertEquals(10, notifyValueChangeEvents[0].value.toInt()) } @@ -66,8 +67,8 @@ class GradleConfiguredValueContainerTest : BackInTimeDebugServiceTest() { val holder = ValueContainerHolder() assertIs(holder) - assertEquals("10", holder.serializeValue(CONTAINER_FQ_NAME, 10)) - assertEquals(10, holder.deserializeValue(CONTAINER_FQ_NAME, "10")) + assertEquals("10", holder.serializeValue(CLASS_FQ_NAME, CONTAINER_NAME, 10)) + assertEquals(10, holder.deserializeValue(CLASS_FQ_NAME, CONTAINER_NAME, "10")) } @Test @@ -75,7 +76,7 @@ class GradleConfiguredValueContainerTest : BackInTimeDebugServiceTest() { val holder = ValueContainerHolder() assertIs(holder) - holder.forceSetValue(CONTAINER_FQ_NAME, 10) + holder.forceSetValue(CLASS_FQ_NAME, CONTAINER_NAME, 10) assertEquals(10, holder.container.value) } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/InheritanceTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/InheritanceTest.kt index 07f26f7c..0169ef5f 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/InheritanceTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/InheritanceTest.kt @@ -11,12 +11,14 @@ import kotlin.test.assertIs class InheritanceTest : BackInTimeDebugServiceTest() { companion object { - private const val SUPER_CLASS_SUPER_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SuperClass.superProperty" - private const val SUPER_CLASS_OVERRIDABLE_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SuperClass.overridableProperty" - private const val SUPER_CLASS_PRIVATE_SUPER_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SuperClass.privateSuperProperty" - private const val SUPER_CLASS_CONFLICTED_PRIVATE_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SuperClass.conflictedPrivateProperty" - private const val SUB_CLASS_SUB_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SubClass.subProperty" - private const val SUB_CLASS_CONFLICTED_PRIVATE_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SubClass.conflictedPrivateProperty" + private const val SUPER_CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SuperClass" + private const val SUPER_PROPERTY_NAME = "superProperty" + private const val OVERRIDABLE_PROPERTY_NAME = "overridableProperty" + private const val PRIVATE_SUPER_PROPERTY_NAME = "privateSuperProperty" + private const val SUPER_CLASS_CONFLICTED_PRIVATE_PROPERTY_NAME = "conflictedPrivateProperty" + private const val SUB_CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.InheritanceTest.SubClass" + private const val SUB_PROPERTY_NAME = "subProperty" + private const val SUB_CLASS_CONFLICTED_PRIVATE_PROPERTY_NAME = "conflictedPrivateProperty" } @BackInTime @@ -58,19 +60,19 @@ class InheritanceTest : BackInTimeDebugServiceTest() { assertIs(instance) // super class - instance.forceSetValue(SUPER_CLASS_SUPER_PROPERTY_FQ_NAME, "super(modified)") + instance.forceSetValue(SUPER_CLASS_FQ_NAME, SUPER_PROPERTY_NAME, "super(modified)") assertEquals("super(modified)", instance.superProperty) // overriding property - instance.forceSetValue(SUPER_CLASS_OVERRIDABLE_PROPERTY_FQ_NAME, "overridable(modified)") + instance.forceSetValue(SUPER_CLASS_FQ_NAME, OVERRIDABLE_PROPERTY_NAME, "overridable(modified)") assertEquals("overridable(modified)", instance.overridableProperty) // sub class - instance.forceSetValue(SUB_CLASS_SUB_PROPERTY_FQ_NAME, "sub(modified)") + instance.forceSetValue(SUB_CLASS_FQ_NAME, SUB_PROPERTY_NAME, "sub(modified)") assertEquals("sub(modified)", instance.subProperty) // private property of super class - instance.forceSetValue(SUPER_CLASS_PRIVATE_SUPER_PROPERTY_FQ_NAME, "private-super(modified)") + instance.forceSetValue(SUPER_CLASS_FQ_NAME, PRIVATE_SUPER_PROPERTY_NAME, "private-super(modified)") assertEquals("private-super(modified)", instance.getPrivateSuperProperty()) } @@ -80,16 +82,16 @@ class InheritanceTest : BackInTimeDebugServiceTest() { assertIs(instance) // super class - assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_SUPER_PROPERTY_FQ_NAME, "string")) + assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_FQ_NAME, SUPER_PROPERTY_NAME, "string")) // overriding property - assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_OVERRIDABLE_PROPERTY_FQ_NAME, "string")) + assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_FQ_NAME, OVERRIDABLE_PROPERTY_NAME, "string")) // sub class - assertEquals("\"string\"", instance.serializeValue(SUB_CLASS_SUB_PROPERTY_FQ_NAME, "string")) + assertEquals("\"string\"", instance.serializeValue(SUB_CLASS_FQ_NAME, SUB_PROPERTY_NAME, "string")) // private property of super class - assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_PRIVATE_SUPER_PROPERTY_FQ_NAME, "string")) + assertEquals("\"string\"", instance.serializeValue(SUPER_CLASS_FQ_NAME, PRIVATE_SUPER_PROPERTY_NAME, "string")) } @Test @@ -98,16 +100,16 @@ class InheritanceTest : BackInTimeDebugServiceTest() { assertIs(instance) // super class - assertEquals("string", instance.deserializeValue(SUPER_CLASS_SUPER_PROPERTY_FQ_NAME, "\"string\"")) + assertEquals("string", instance.deserializeValue(SUPER_CLASS_FQ_NAME, SUPER_PROPERTY_NAME, "\"string\"")) // overriding property - assertEquals("string", instance.deserializeValue(SUPER_CLASS_OVERRIDABLE_PROPERTY_FQ_NAME, "\"string\"")) + assertEquals("string", instance.deserializeValue(SUPER_CLASS_FQ_NAME, OVERRIDABLE_PROPERTY_NAME, "\"string\"")) // sub class - assertEquals("string", instance.deserializeValue(SUB_CLASS_SUB_PROPERTY_FQ_NAME, "\"string\"")) + assertEquals("string", instance.deserializeValue(SUB_CLASS_FQ_NAME, SUB_PROPERTY_NAME, "\"string\"")) // private property of super class - assertEquals("string", instance.deserializeValue(SUPER_CLASS_PRIVATE_SUPER_PROPERTY_FQ_NAME, "\"string\"")) + assertEquals("string", instance.deserializeValue(SUPER_CLASS_FQ_NAME, PRIVATE_SUPER_PROPERTY_NAME, "\"string\"")) } @Test @@ -115,11 +117,11 @@ class InheritanceTest : BackInTimeDebugServiceTest() { val instance = SubClass() assertIs(instance) - instance.forceSetValue(SUB_CLASS_CONFLICTED_PRIVATE_PROPERTY_FQ_NAME, "conflict(update-sub)") + instance.forceSetValue(SUB_CLASS_FQ_NAME, SUB_CLASS_CONFLICTED_PRIVATE_PROPERTY_NAME, "conflict(update-sub)") assertEquals(expected = "conflict(update-sub)", actual = instance.getSubPrivateConflictedProperty()) assertEquals(expected = "conflict", actual = instance.getSuperPrivateConflictedProperty()) - instance.forceSetValue(SUPER_CLASS_CONFLICTED_PRIVATE_PROPERTY_FQ_NAME, "conflict(update-super)") + instance.forceSetValue(SUPER_CLASS_FQ_NAME, SUPER_CLASS_CONFLICTED_PRIVATE_PROPERTY_NAME, "conflict(update-super)") assertEquals(expected = "conflict(update-sub)", actual = instance.getSubPrivateConflictedProperty()) assertEquals(expected = "conflict(update-super)", actual = instance.getSuperPrivateConflictedProperty()) } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/PureVarsHolderTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/PureVarsHolderTest.kt index 0e10bc9d..ae0f273a 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/PureVarsHolderTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/PureVarsHolderTest.kt @@ -9,7 +9,6 @@ import kotlin.test.assertIs class PureVarsHolderTest { companion object { private const val HOLDER_CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.PureVarsHolderTest.PureVarsHolder" - private fun String.toFQN() = "$HOLDER_CLASS_FQ_NAME.$this" } @BackInTime @@ -45,15 +44,15 @@ class PureVarsHolderTest { val holder = PureVarsHolder() assertIs(holder) - assertEquals("\"hogehoge\"", holder.serializeValue("string".toFQN(), "hogehoge")) - assertEquals("1000", holder.serializeValue("int".toFQN(), 1000)) - assertEquals("10000000000", holder.serializeValue("long".toFQN(), 10000000000L)) - assertEquals("0.1", holder.serializeValue("float".toFQN(), 0.1f)) - assertEquals("0.001", holder.serializeValue("double".toFQN(), 0.001)) - assertEquals("true", holder.serializeValue("boolean".toFQN(), true)) - assertEquals("\"b\"", holder.serializeValue("char".toFQN(), 'b')) - assertEquals("100", holder.serializeValue("short".toFQN(), 100.toShort())) - assertEquals("100", holder.serializeValue("byte".toFQN(), 100.toByte())) + assertEquals("\"hogehoge\"", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "string", "hogehoge")) + assertEquals("1000", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "int", 1000)) + assertEquals("10000000000", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "long", 10000000000L)) + assertEquals("0.1", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "float", 0.1f)) + assertEquals("0.001", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "double", 0.001)) + assertEquals("true", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "boolean", true)) + assertEquals("\"b\"", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "char", 'b')) + assertEquals("100", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "short", 100.toShort())) + assertEquals("100", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "byte", 100.toByte())) } @Test @@ -61,12 +60,12 @@ class PureVarsHolderTest { val holder = PureVarsHolder() assertIs(holder) - assertEquals("[\"string value\"]", holder.serializeValue("stringList".toFQN(), listOf("string value"))) - assertEquals("[0]", holder.serializeValue("intList".toFQN(), listOf(0))) - assertEquals("[0]", holder.serializeValue("longList".toFQN(), listOf(0L))) - assertEquals("[0.0]", holder.serializeValue("floatList".toFQN(), listOf(0f))) - assertEquals("[0.0]", holder.serializeValue("doubleList".toFQN(), listOf(0.0))) - assertEquals("[false]", holder.serializeValue("booleanList".toFQN(), listOf(false))) + assertEquals("[\"string value\"]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "stringList", listOf("string value"))) + assertEquals("[0]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "intList", listOf(0))) + assertEquals("[0]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "longList", listOf(0L))) + assertEquals("[0.0]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "floatList", listOf(0f))) + assertEquals("[0.0]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "doubleList", listOf(0.0))) + assertEquals("[false]", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "booleanList", listOf(false))) } @Test @@ -74,15 +73,15 @@ class PureVarsHolderTest { val holder = PureVarsHolder() assertIs(holder) - assertEquals("null", holder.serializeValue("nullableString".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableInt".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableLong".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableFloat".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableDouble".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableBoolean".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableChar".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableShort".toFQN(), null)) - assertEquals("null", holder.serializeValue("nullableByte".toFQN(), null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableString", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableInt", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableLong", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableFloat", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableDouble", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableBoolean", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableChar", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableShort", null)) + assertEquals("null", holder.serializeValue(HOLDER_CLASS_FQ_NAME, "nullableByte", null)) } @Test @@ -90,42 +89,42 @@ class PureVarsHolderTest { val holder = PureVarsHolder() assertIs(holder) - assertEquals("hogehoge", holder.deserializeValue("string".toFQN(), "\"hogehoge\"")) - assertEquals(0, holder.deserializeValue("int".toFQN(), "0")) - assertEquals(0L, holder.deserializeValue("long".toFQN(), "0")) - assertEquals(0f, holder.deserializeValue("float".toFQN(), "0.0")) - assertEquals(0.0, holder.deserializeValue("double".toFQN(), "0.0")) - assertEquals(false, holder.deserializeValue("boolean".toFQN(), "false")) - assertEquals('a', holder.deserializeValue("char".toFQN(), "\"a\"")) - assertEquals(0.toShort(), holder.deserializeValue("short".toFQN(), "0")) - assertEquals(0.toByte(), holder.deserializeValue("byte".toFQN(), "0")) + assertEquals("hogehoge", holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "string", "\"hogehoge\"")) + assertEquals(0, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "int", "0")) + assertEquals(0L, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "long", "0")) + assertEquals(0f, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "float", "0.0")) + assertEquals(0.0, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "double", "0.0")) + assertEquals(false, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "boolean", "false")) + assertEquals('a', holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "char", "\"a\"")) + assertEquals(0.toShort(), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "short", "0")) + assertEquals(0.toByte(), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "byte", "0")) } @Test fun deserializeNonNullCollectionFields() { val holder = PureVarsHolder() assertIs(holder) - assertEquals(listOf("string value"), holder.deserializeValue("stringList".toFQN(), "[\"string value\"]")) - assertEquals(listOf(0), holder.deserializeValue("intList".toFQN(), "[0]")) - assertEquals(listOf(0L), holder.deserializeValue("longList".toFQN(), "[0]")) - assertEquals(listOf(0f), holder.deserializeValue("floatList".toFQN(), "[0.0]")) - assertEquals(listOf(0.0), holder.deserializeValue("doubleList".toFQN(), "[0.0]")) - assertEquals(listOf(false), holder.deserializeValue("booleanList".toFQN(), "[false]")) + assertEquals(listOf("string value"), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "stringList", "[\"string value\"]")) + assertEquals(listOf(0), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "intList", "[0]")) + assertEquals(listOf(0L), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "longList", "[0]")) + assertEquals(listOf(0f), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "floatList", "[0.0]")) + assertEquals(listOf(0.0), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "doubleList", "[0.0]")) + assertEquals(listOf(false), holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "booleanList", "[false]")) } @Test fun deserializeNullableFields() { val holder = PureVarsHolder() assertIs(holder) - assertEquals(null, holder.deserializeValue("nullableString".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableInt".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableLong".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableFloat".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableDouble".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableBoolean".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableChar".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableShort".toFQN(), "null")) - assertEquals(null, holder.deserializeValue("nullableByte".toFQN(), "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableString", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableInt", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableLong", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableFloat", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableDouble", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableBoolean", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableChar", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableShort", "null")) + assertEquals(null, holder.deserializeValue(HOLDER_CLASS_FQ_NAME, "nullableByte", "null")) } @Test @@ -133,41 +132,41 @@ class PureVarsHolderTest { val holder = PureVarsHolder() assertIs(holder) - holder.forceSetValue("string".toFQN(), "hogehoge") + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "string", "hogehoge") assertEquals("hogehoge", holder.string) - holder.forceSetValue("int".toFQN(), 0) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "int", 0) assertEquals(0, holder.int) - holder.forceSetValue("long".toFQN(), 0L) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "long", 0L) assertEquals(0L, holder.long) - holder.forceSetValue("float".toFQN(), 0f) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "float", 0f) assertEquals(0f, holder.float) - holder.forceSetValue("double".toFQN(), 0.0) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "double", 0.0) assertEquals(0.0, holder.double) - holder.forceSetValue("boolean".toFQN(), false) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "boolean", false) assertEquals(false, holder.boolean) - holder.forceSetValue("char".toFQN(), 'a') + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "char", 'a') assertEquals('a', holder.char) - holder.forceSetValue("short".toFQN(), 0.toShort()) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "short", 0.toShort()) assertEquals(0.toShort(), holder.short) - holder.forceSetValue("byte".toFQN(), 0.toByte()) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "byte", 0.toByte()) assertEquals(0.toByte(), holder.byte) - holder.forceSetValue("nullableString".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableString", null) assertEquals(null, holder.nullableString) - holder.forceSetValue("nullableInt".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableInt", null) assertEquals(null, holder.nullableInt) - holder.forceSetValue("nullableLong".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableLong", null) assertEquals(null, holder.nullableLong) - holder.forceSetValue("nullableFloat".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableFloat", null) assertEquals(null, holder.nullableFloat) - holder.forceSetValue("nullableDouble".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableDouble", null) assertEquals(null, holder.nullableDouble) - holder.forceSetValue("nullableBoolean".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableBoolean", null) assertEquals(null, holder.nullableBoolean) - holder.forceSetValue("nullableChar".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableChar", null) assertEquals(null, holder.nullableChar) - holder.forceSetValue("nullableShort".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableShort", null) assertEquals(null, holder.nullableShort) - holder.forceSetValue("nullableByte".toFQN(), null) + holder.forceSetValue(HOLDER_CLASS_FQ_NAME, "nullableByte", null) assertEquals(null, holder.nullableByte) } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/ScopeFunctionsTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/ScopeFunctionsTest.kt index aa46538c..2895d153 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/ScopeFunctionsTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/ScopeFunctionsTest.kt @@ -15,7 +15,8 @@ import kotlin.test.assertIs class ScopeFunctionsTest : BackInTimeDebugServiceTest() { companion object { - private const val CONTAINER_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.ScopeFunctionsTest.ValueContainerHolder.container" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.ScopeFunctionsTest.ValueContainerHolder" + private const val CONTAINER_PROPERTY_NAME = "container" } @ValueContainer @@ -129,7 +130,8 @@ class ScopeFunctionsTest : BackInTimeDebugServiceTest() { assertEquals(10, container.value) assertEquals(1, notifyValueChangeEvents.size) assertEquals(this.backInTimeInstanceUUID, notifyValueChangeEvents[0].instanceUUID) - assertEquals(CONTAINER_PROPERTY_FQ_NAME, notifyValueChangeEvents[0].propertyFqName) + assertEquals(CLASS_FQ_NAME, notifyValueChangeEvents[0].ownerClassFqName) + assertEquals(CONTAINER_PROPERTY_NAME, notifyValueChangeEvents[0].propertyName) assertEquals(10, notifyValueChangeEvents[0].value.toInt()) } } diff --git a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/SelfSerializableValueHolderTest.kt b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/SelfSerializableValueHolderTest.kt index 2ff7daab..f0884103 100644 --- a/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/SelfSerializableValueHolderTest.kt +++ b/test/src/commonTest/kotlin/com/github/kitakkun/backintime/test/specific/SelfSerializableValueHolderTest.kt @@ -8,7 +8,8 @@ import kotlin.test.assertIs class SelfSerializableValueHolderTest { companion object { - private const val MUTABLE_LIST_PROPERTY_FQ_NAME = "com.github.kitakkun.backintime.test.specific.SelfSerializableValueHolderTest.TestStateHolder.mutableList" + private const val CLASS_FQ_NAME = "com.github.kitakkun.backintime.test.specific.SelfSerializableValueHolderTest.TestStateHolder" + private const val MUTABLE_LIST_PROPERTY_NAME = "mutableList" } @BackInTime @@ -22,7 +23,7 @@ class SelfSerializableValueHolderTest { assertIs(holder) val input = listOf("Hello") - val serializedValue = holder.serializeValue(MUTABLE_LIST_PROPERTY_FQ_NAME, input) + val serializedValue = holder.serializeValue(CLASS_FQ_NAME, MUTABLE_LIST_PROPERTY_NAME, input) assertEquals("[\"Hello\"]", serializedValue) } @@ -32,7 +33,7 @@ class SelfSerializableValueHolderTest { assertIs(holder) val input = "[\"Hello\"]" - val deserializedValue = holder.deserializeValue(MUTABLE_LIST_PROPERTY_FQ_NAME, input) + val deserializedValue = holder.deserializeValue(CLASS_FQ_NAME, MUTABLE_LIST_PROPERTY_NAME, input) assertEquals(listOf("Hello"), deserializedValue) } @@ -42,7 +43,7 @@ class SelfSerializableValueHolderTest { assertIs(holder) val input = listOf("Hello") - holder.forceSetValue(MUTABLE_LIST_PROPERTY_FQ_NAME, input) + holder.forceSetValue(CLASS_FQ_NAME, MUTABLE_LIST_PROPERTY_NAME, input) assertEquals(listOf("Hello"), holder.mutableList) } } From 9fdfff4a933939a19ea053d30fbe779820009779 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Fri, 5 Jul 2024 23:48:06 +0900 Subject: [PATCH 3/9] rename properties and remove unused 'valueType' property --- .../backintime/runtime/BackInTimeDebugServiceImpl.kt | 4 ++-- .../backintime/websocket/event/BackInTimeDebuggerEvent.kt | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt index a74a52e8..e7fc2ffc 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/BackInTimeDebugServiceImpl.kt @@ -105,8 +105,8 @@ class BackInTimeDebugServiceImpl( is BackInTimeDebuggerEvent.ForceSetPropertyValue -> { forceSetValue( instanceId = event.instanceUUID, - propertyOwnerClassName = event.propertyOwnerClassName, - propertyName = event.propertyFqName, + propertyOwnerClassName = event.ownerClassFqName, + propertyName = event.propertyName, value = event.value, ) null diff --git a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt index ca519bef..79feb531 100644 --- a/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt +++ b/backintime-websocket-event/src/commonMain/kotlin/com/github/kitakkun/backintime/websocket/event/BackInTimeDebuggerEvent.kt @@ -23,10 +23,9 @@ sealed class BackInTimeDebuggerEvent { @Serializable data class ForceSetPropertyValue( val instanceUUID: String, - val propertyFqName: String, - val propertyOwnerClassName: String, + val ownerClassFqName: String, + val propertyName: String, val value: String, - val valueType: String, ) : BackInTimeDebuggerEvent() @Serializable From a1ca228037ac0a66501227f6dfe8cf9b5b758459 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:21:54 +0900 Subject: [PATCH 4/9] check if typescript sources will compile on CI --- .github/workflows/review.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/review.yaml b/.github/workflows/review.yaml index a5023625..329534db 100644 --- a/.github/workflows/review.yaml +++ b/.github/workflows/review.yaml @@ -53,5 +53,9 @@ jobs: - run: yarn install working-directory: backintime-flipper-plugin + - name: compile typescript + run: npx tsc + working-directory: backintime-flipper-plugin + - run: yarn test working-directory: backintime-flipper-plugin From 63b8fae2104b6f9e13c324d5c9a1d45345467315 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 10:22:51 +0900 Subject: [PATCH 5/9] add types/uuid to devDependencies --- backintime-flipper-plugin/package.json | 5 +++-- backintime-flipper-plugin/yarn.lock | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/backintime-flipper-plugin/package.json b/backintime-flipper-plugin/package.json index 872193cb..53853591 100644 --- a/backintime-flipper-plugin/package.json +++ b/backintime-flipper-plugin/package.json @@ -37,6 +37,7 @@ "@types/jest": "latest", "@types/react": "latest", "@types/react-dom": "latest", + "@types/uuid": "^10.0.0", "antd": "^5.11.5", "babel-jest": "^29.7.0", "flipper-pkg": "latest", @@ -65,8 +66,8 @@ "@mui/material": "^5.14.18", "@reduxjs/toolkit": "^1.9.7", "@textea/json-viewer": "^3.2.3", + "kmp-lib": "file:../backintime-websocket-event/build/dist/js/productionLibrary", "react-icons": "^5.0.1", - "react-redux": "^8.1.3", - "kmp-lib": "file:../backintime-websocket-event/build/dist/js/productionLibrary" + "react-redux": "^8.1.3" } } diff --git a/backintime-flipper-plugin/yarn.lock b/backintime-flipper-plugin/yarn.lock index 3dfb4772..18436fee 100644 --- a/backintime-flipper-plugin/yarn.lock +++ b/backintime-flipper-plugin/yarn.lock @@ -2850,6 +2850,11 @@ resolved "https://registry.yarnpkg.com/@types/use-sync-external-store/-/use-sync-external-store-0.0.3.tgz#b6725d5f4af24ace33b36fafd295136e75509f43" integrity sha512-EwmlvuaxPNej9+T4v5AuBPJa2x2UOJVdjCtDHgcDqitUeOtjnJKJ+apYjVcAoBEMjKW1VVFGZLUb5+qqa09XFA== +"@types/uuid@^10.0.0": + version "10.0.0" + resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-10.0.0.tgz#e9c07fe50da0f53dc24970cca94d619ff03f6f6d" + integrity sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ== + "@types/yargs-parser@*": version "21.0.2" resolved "https://registry.yarnpkg.com/@types/yargs-parser/-/yargs-parser-21.0.2.tgz#7bd04c5da378496ef1695a1008bf8f71847a8b8b" From 904cc97541ab1815cf8be6d7bffcb239073af35a Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 18:13:30 +0900 Subject: [PATCH 6/9] rename kmp-lib to backintime-websocket-event --- backintime-flipper-plugin/package.json | 2 +- backintime-flipper-plugin/src/BackInTimePlugin.tsx | 2 +- .../src/__tests__/test.incomingEvents.tsx | 2 +- .../src/events/FlipperIncomingEvents.tsx | 2 +- .../src/events/FlipperOutgoingEvents.tsx | 2 +- backintime-flipper-plugin/src/reducer/appReducer.tsx | 2 +- .../src/view/page/backintime/BackInTimeModalPage.tsx | 2 +- .../edited_value_emitter/EditAndEmitValueModalPage.tsx | 2 +- .../src/view/page/instance_list/InstanceListPage.tsx | 2 +- .../src/view/page/value_emit/ValueEmitModalPage.tsx | 2 +- backintime-flipper-plugin/yarn.lock | 10 +++++----- 11 files changed, 15 insertions(+), 15 deletions(-) diff --git a/backintime-flipper-plugin/package.json b/backintime-flipper-plugin/package.json index 53853591..e96b968a 100644 --- a/backintime-flipper-plugin/package.json +++ b/backintime-flipper-plugin/package.json @@ -66,7 +66,7 @@ "@mui/material": "^5.14.18", "@reduxjs/toolkit": "^1.9.7", "@textea/json-viewer": "^3.2.3", - "kmp-lib": "file:../backintime-websocket-event/build/dist/js/productionLibrary", + "backintime-websocket-event": "file:../backintime-websocket-event/build/dist/js/productionLibrary", "react-icons": "^5.0.1", "react-redux": "^8.1.3" } diff --git a/backintime-flipper-plugin/src/BackInTimePlugin.tsx b/backintime-flipper-plugin/src/BackInTimePlugin.tsx index fdf3916d..89b8e9f2 100644 --- a/backintime-flipper-plugin/src/BackInTimePlugin.tsx +++ b/backintime-flipper-plugin/src/BackInTimePlugin.tsx @@ -12,7 +12,7 @@ import {editAndEmitValueReducer} from "./view/page/edited_value_emitter/EditAndE import {AtomicPersistentState, initPersistentStateSlice, persistentStateReducer} from "./reducer/PersistentStateReducer"; import {rawLogInspectorReducer} from "./view/sidebar/raw_log_inspector/RawLogInspectorReducer"; import {backInTimeReducer} from "./view/page/backintime/BackInTimeReducer"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; export default (client: PluginClient) => { diff --git a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx index 43b3065d..8e3fbecd 100644 --- a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx +++ b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx @@ -4,7 +4,7 @@ import {InstanceInfo} from "../data/InstanceInfo"; import {AppState} from "../reducer/appReducer"; import {ClassInfo} from "../data/ClassInfo"; import {MethodCallInfo} from "../data/MethodCallInfo"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import NotifyMethodCall = com.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent.NotifyMethodCall; import NotifyValueChange = com.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent.NotifyValueChange; diff --git a/backintime-flipper-plugin/src/events/FlipperIncomingEvents.tsx b/backintime-flipper-plugin/src/events/FlipperIncomingEvents.tsx index 192235b1..a6129f76 100644 --- a/backintime-flipper-plugin/src/events/FlipperIncomingEvents.tsx +++ b/backintime-flipper-plugin/src/events/FlipperIncomingEvents.tsx @@ -1,4 +1,4 @@ -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebugServiceEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent; export type IncomingEvents = { diff --git a/backintime-flipper-plugin/src/events/FlipperOutgoingEvents.tsx b/backintime-flipper-plugin/src/events/FlipperOutgoingEvents.tsx index 67008d8b..d01dcd25 100644 --- a/backintime-flipper-plugin/src/events/FlipperOutgoingEvents.tsx +++ b/backintime-flipper-plugin/src/events/FlipperOutgoingEvents.tsx @@ -1,4 +1,4 @@ -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; import BackInTimeDebugServiceEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent; diff --git a/backintime-flipper-plugin/src/reducer/appReducer.tsx b/backintime-flipper-plugin/src/reducer/appReducer.tsx index 1328e9eb..1c1732df 100644 --- a/backintime-flipper-plugin/src/reducer/appReducer.tsx +++ b/backintime-flipper-plugin/src/reducer/appReducer.tsx @@ -3,7 +3,7 @@ import {ClassInfo} from "../data/ClassInfo"; import {InstanceInfo} from "../data/InstanceInfo"; import {MethodCallInfo} from "../data/MethodCallInfo"; import {DependencyInfo} from "../data/DependencyInfo"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; import BackInTimeDebugServiceEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebugServiceEvent; diff --git a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx index 6d25b045..d3b5a1be 100644 --- a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx +++ b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx @@ -6,7 +6,7 @@ import {backInTimeStateSelector} from "./BackInTimeSelector"; import {MethodCallHistoryInfo} from "./HistoryInfo"; import {appActions} from "../../../reducer/appReducer"; import {backInTimeActions} from "./BackInTimeReducer"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; export function BackInTimeModalPage() { diff --git a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx index 76cac56b..9c305175 100644 --- a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx +++ b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx @@ -4,7 +4,7 @@ import {EditAndEmitValueView} from "./EditAndEmitValueView"; import React from "react"; import {Modal} from "antd"; import {appActions} from "../../../reducer/appReducer"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; export function EditAndEmitValueModalPage() { diff --git a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx index 75037961..ab2a42ea 100644 --- a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx +++ b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx @@ -7,7 +7,7 @@ import {appActions} from "../../../reducer/appReducer"; import {propertyInspectorActions} from "../../sidebar/property_inspector/propertyInspectorReducer"; import {backInTimeActions} from "../backintime/BackInTimeReducer"; import {BackInTimeModalPage} from "../backintime/BackInTimeModalPage"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import createCheckInstanceAliveEvent = com.github.kitakkun.backintime.websocket.event.createCheckInstanceAliveEvent; export function InstanceListPage() { diff --git a/backintime-flipper-plugin/src/view/page/value_emit/ValueEmitModalPage.tsx b/backintime-flipper-plugin/src/view/page/value_emit/ValueEmitModalPage.tsx index 03e4af60..ce046879 100644 --- a/backintime-flipper-plugin/src/view/page/value_emit/ValueEmitModalPage.tsx +++ b/backintime-flipper-plugin/src/view/page/value_emit/ValueEmitModalPage.tsx @@ -6,7 +6,7 @@ import {Modal} from "antd"; import {editAndEmitValueActions} from "../edited_value_emitter/EditAndEmitValueReducer"; import {appActions} from "../../../reducer/appReducer"; import {EditAndEmitValueModalPage} from "../edited_value_emitter/EditAndEmitValueModalPage"; -import {com} from "kmp-lib"; +import {com} from "backintime-websocket-event"; import BackInTimeDebuggerEvent = com.github.kitakkun.backintime.websocket.event.BackInTimeDebuggerEvent; export function ValueEmitModalPage() { diff --git a/backintime-flipper-plugin/yarn.lock b/backintime-flipper-plugin/yarn.lock index 18436fee..620e1e11 100644 --- a/backintime-flipper-plugin/yarn.lock +++ b/backintime-flipper-plugin/yarn.lock @@ -3317,6 +3317,11 @@ babel-preset-jest@^29.6.3: babel-plugin-jest-hoist "^29.6.3" babel-preset-current-node-syntax "^1.0.0" +"backintime-websocket-event@file:../backintime-websocket-event/build/dist/js/productionLibrary": + version "1.0.0" + dependencies: + format-util "^1.0.5" + balanced-match@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.2.tgz#e83e3a7e3f300b34cb9d87f615fa0cbf357690ee" @@ -5914,11 +5919,6 @@ kleur@^3.0.3: resolved "https://registry.yarnpkg.com/kleur/-/kleur-3.0.3.tgz#a79c9ecc86ee1ce3fa6206d1216c501f147fc07e" integrity sha512-eTIzlVOSUR+JxdDFepEYcBMtZ9Qqdef+rnzWdRZuMbOywu5tO2w2N7rqjoANZ5k9vywhL6Br1VRjUIgTQx4E8w== -"kmp-lib@file:../backintime-websocket-event/build/dist/js/productionLibrary": - version "1.0.0" - dependencies: - format-util "^1.0.5" - lazy-cache@^2.0.1: version "2.0.2" resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-2.0.2.tgz#b9190a4f913354694840859f8a8f7084d8822264" From e10a7d04c9bcda56e5ea60d066ba486711093da5 Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 19:04:11 +0900 Subject: [PATCH 7/9] fix comment (fqName -> name) --- .../runtime/event/BackInTimeDebuggableInstanceEvent.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt index b37fc29c..d7e0276f 100644 --- a/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt +++ b/backintime-runtime/src/commonMain/kotlin/com/github/kitakkun/backintime/runtime/event/BackInTimeDebuggableInstanceEvent.kt @@ -49,7 +49,7 @@ sealed interface BackInTimeDebuggableInstanceEvent { * Notify that a property value is changed * @param instance the reference to the instance * @param methodCallId the unique id of the method call - * @param propertyName the fqName of the property. + * @param propertyName the name of the property. * @param propertyValue the value of the property */ data class PropertyValueChange( From c808ac4a00fdf1842c8ed5ce0312e74202b5863a Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 19:52:30 +0900 Subject: [PATCH 8/9] fix the flipper plugin implementation --- backintime-flipper-plugin/.gitignore | 3 ++- .../src/__tests__/test.incomingEvents.tsx | 8 ++++++-- .../src/data/MethodCallInfo.tsx | 4 +++- backintime-flipper-plugin/src/reducer/appReducer.tsx | 4 +++- .../src/view/page/backintime/BackInTimeModalPage.tsx | 12 +++++------- .../src/view/page/backintime/BackInTimeSelector.tsx | 2 +- .../EditAndEmitValueModalPage.tsx | 4 ++-- .../edited_value_emitter/EditAndEmitValueReducer.tsx | 3 ++- .../edited_value_emitter/EditAndEmitValueView.tsx | 3 ++- .../src/view/page/instance_list/InstanceListPage.tsx | 3 +-- .../view/page/instance_list/InstanceListSelector.tsx | 2 +- .../view/page/value_emit/ChangedPropertiesView.tsx | 2 +- .../src/view/page/value_emit/ValueEmitModalPage.tsx | 6 +++--- .../PropertyInspectorStateSelector.tsx | 4 ++-- 14 files changed, 34 insertions(+), 26 deletions(-) diff --git a/backintime-flipper-plugin/.gitignore b/backintime-flipper-plugin/.gitignore index bbe09586..277ec51a 100644 --- a/backintime-flipper-plugin/.gitignore +++ b/backintime-flipper-plugin/.gitignore @@ -2,4 +2,5 @@ node_modules dist/ .idea/* !.idea/codeStyles -*.tgz \ No newline at end of file +*.tgz +*.map diff --git a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx index 8e3fbecd..8049f2a4 100644 --- a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx +++ b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx @@ -71,6 +71,7 @@ test(`notifyMethodCall event`, () => { sendEvent("notifyMethodCall", { methodName: "hoge", + ownerClassFqName: "com.example.MyClass", instanceUUID: "7fd43b42-f951-4307-a997-85f6074c17c9", methodCallUUID: "jf245181-8d9f-4d9e-9a7b-1a7f4b6f0b3e", calledAt: 1619813420, @@ -80,6 +81,7 @@ test(`notifyMethodCall event`, () => { expect(state.methodCallInfoList[0]).toEqual({ instanceUUID: "7fd43b42-f951-4307-a997-85f6074c17c9", + ownerClassFqName: "com.example.MyClass", methodName: "hoge", callUUID: "jf245181-8d9f-4d9e-9a7b-1a7f4b6f0b3e", calledAt: 1619813420, @@ -97,6 +99,7 @@ test(`notifyValueChange event`, () => { sendEvent("notifyMethodCall", { methodName: "hoge", + ownerClassFqName: "com.example.MyClass", instanceUUID: instanceUUID, methodCallUUID: methodCallUUID, calledAt: calledAt, @@ -104,7 +107,8 @@ test(`notifyValueChange event`, () => { sendEvent("notifyValueChange", { instanceUUID: instanceUUID, - propertyFqName: "hoge", + ownerClassFqName: "com.example.MyClass", + propertyName: "hoge", value: "fuga", methodCallUUID: methodCallUUID, } as NotifyValueChange); @@ -116,7 +120,7 @@ test(`notifyValueChange event`, () => { calledAt: calledAt, valueChanges: [ { - propertyFqName: "hoge", + propertyName: "hoge", value: "fuga", } ], diff --git a/backintime-flipper-plugin/src/data/MethodCallInfo.tsx b/backintime-flipper-plugin/src/data/MethodCallInfo.tsx index ff4b44d6..e21e4768 100644 --- a/backintime-flipper-plugin/src/data/MethodCallInfo.tsx +++ b/backintime-flipper-plugin/src/data/MethodCallInfo.tsx @@ -1,4 +1,5 @@ export interface MethodCallInfo { + ownerClassFqName: string; callUUID: string; instanceUUID: string; methodName: string; @@ -7,6 +8,7 @@ export interface MethodCallInfo { } export interface ValueChangeInfo { - propertyFqName: string; + ownerClassFqName: string; + propertyName: string; value: string; } diff --git a/backintime-flipper-plugin/src/reducer/appReducer.tsx b/backintime-flipper-plugin/src/reducer/appReducer.tsx index 1c1732df..03f89a26 100644 --- a/backintime-flipper-plugin/src/reducer/appReducer.tsx +++ b/backintime-flipper-plugin/src/reducer/appReducer.tsx @@ -85,6 +85,7 @@ const appSlice = createSlice({ registerMethodCall: (state, action: PayloadAction) => { const event = action.payload; state.methodCallInfoList.push({ + ownerClassFqName: event.ownerClassFqName, callUUID: event.methodCallUUID, instanceUUID: event.instanceUUID, methodName: event.methodName, @@ -97,7 +98,8 @@ const appSlice = createSlice({ const methodCallInfo = state.methodCallInfoList.find((info) => info.callUUID == event.methodCallUUID); if (!methodCallInfo) return; methodCallInfo.valueChanges.push({ - propertyFqName: event.propertyFqName, + ownerClassFqName: event.ownerClassFqName, + propertyName: event.propertyName, value: event.value, }); }, diff --git a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx index d3b5a1be..61ab180e 100644 --- a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx +++ b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeModalPage.tsx @@ -34,15 +34,13 @@ export function BackInTimeModalPage() { .filter((history) => history.title == "methodCall") .map((history) => history as MethodCallHistoryInfo); const allValueChanges = methodCallHistories.flatMap((history) => history.valueChanges); - const properties = distinctBy(allValueChanges.map((valueChange) => valueChange.propertyFqName), (name) => name); - properties.forEach((name) => { - const value = allValueChanges.reverse().find((valueChange) => valueChange.propertyFqName == name)?.value; - if (!value) return; + const propertyValueChanges = distinctBy(allValueChanges.reverse(), (valueChange) => valueChange.ownerClassFqName + valueChange.propertyName); + propertyValueChanges.forEach((info) => { const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue( state.instanceUUID, - name, - value, - "", // 使われてないから大丈夫 + info.ownerClassFqName, + info.propertyName, + info.value, ); dispatch(appActions.forceSetPropertyValue(event)); }); diff --git a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeSelector.tsx b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeSelector.tsx index 83c03de6..084dd3d2 100644 --- a/backintime-flipper-plugin/src/view/page/backintime/BackInTimeSelector.tsx +++ b/backintime-flipper-plugin/src/view/page/backintime/BackInTimeSelector.tsx @@ -31,7 +31,7 @@ export const backInTimeStateSelector = createSelector( title: "methodCall", timestamp: info.calledAt, subtitle: info.methodName, - description: info.valueChanges.map((change) => `${change.propertyFqName} = ${change.value}`).join(", "), + description: info.valueChanges.map((change) => `${change.propertyName} = ${change.value}`).join(", "), valueChanges: info.valueChanges, } as HistoryInfo; }); diff --git a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx index 9c305175..f47c5286 100644 --- a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx +++ b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueModalPage.tsx @@ -18,12 +18,12 @@ export function EditAndEmitValueModalPage() { cancelText={"Cancel"} okText={"Emit Edited Value"} onOk={() => { - if (!state.instanceUUID || !state.propertyName || !state.valueType) return; + if (!state.instanceUUID || !state.propertyName || !state.valueType || !state.ownerClassFqName) return; const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue( state.instanceUUID, + state.ownerClassFqName, state.propertyName, JSON.stringify(state.editingValue), - state.valueType, ); dispatch(appActions.forceSetPropertyValue(event)); dispatch(editAndEmitValueActions.close()); diff --git a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueReducer.tsx b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueReducer.tsx index 93807674..ae3c9fe2 100644 --- a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueReducer.tsx +++ b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueReducer.tsx @@ -58,6 +58,7 @@ export const editAndEmitValueStateSelector = createSelector( return { ...state, valueType: valueType, + ownerClassFqName: classInfo?.name, } as EditAndEmitState; } -); \ No newline at end of file +); diff --git a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueView.tsx b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueView.tsx index 1105d3b1..5ad25a33 100644 --- a/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueView.tsx +++ b/backintime-flipper-plugin/src/view/page/edited_value_emitter/EditAndEmitValueView.tsx @@ -8,6 +8,7 @@ export interface EditAndEmitState { editingValue: any; open: boolean; instanceUUID: string; + ownerClassFqName: string; propertyName: string; valueType: string | undefined; } @@ -34,4 +35,4 @@ export function EditAndEmitValueView({state, onEdit}: EditAndEmitValueViewProps) ); -} \ No newline at end of file +} diff --git a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx index ab2a42ea..b5cedd7e 100644 --- a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx +++ b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListPage.tsx @@ -27,8 +27,7 @@ export function InstanceListPage() { onClickRefresh={() => { const uuids = state.instances.map((info) => info.uuid); if (uuids.length == 0) return; - const event = createCheckInstanceAliveEvent(uuids); - dispatch(appActions.refreshInstanceAliveStatuses(event)); + dispatch(appActions.refreshInstanceAliveStatuses(createCheckInstanceAliveEvent(uuids))); }} onChangeNonDebuggablePropertyVisible={(visible) => { dispatch(persistentStateActions().updateNonDebuggablePropertyVisibility(visible)); diff --git a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListSelector.tsx b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListSelector.tsx index 24f9bbb0..ad9feaf5 100644 --- a/backintime-flipper-plugin/src/view/page/instance_list/InstanceListSelector.tsx +++ b/backintime-flipper-plugin/src/view/page/instance_list/InstanceListSelector.tsx @@ -54,7 +54,7 @@ function resolveInstanceInfo( name: property.name, type: property.type, debuggable: property.debuggable, - eventCount: allValueChangeEvents.filter((event) => event.propertyFqName == `${classInfo.name}.${property.name}`).length, + eventCount: allValueChangeEvents.filter((event) => event.propertyName == property.name && classInfo.name == event.ownerClassFqName).length, stateHolderInstance: propertyInstanceInfo && resolveInstanceInfo( classInfoList, instanceInfoList, diff --git a/backintime-flipper-plugin/src/view/page/value_emit/ChangedPropertiesView.tsx b/backintime-flipper-plugin/src/view/page/value_emit/ChangedPropertiesView.tsx index 3c1060c5..17c78456 100644 --- a/backintime-flipper-plugin/src/view/page/value_emit/ChangedPropertiesView.tsx +++ b/backintime-flipper-plugin/src/view/page/value_emit/ChangedPropertiesView.tsx @@ -22,7 +22,7 @@ type ValueChangeItem = { export function ChangedPropertiesView({classInfo, methodCallInfo, onClickEmitValue, onClickEditAndEmitValue}: ChangedPropertiesViewProps) { const dataSource: ValueChangeItem[] = methodCallInfo.valueChanges.map((valueChange) => { // FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class. - const property = classInfo.properties.find((property) => property.name === valueChange.propertyFqName.split(".").pop())!; + const property = classInfo.properties.find((property) => property.name === valueChange.propertyName)!; const jsonValue = JSON.parse(valueChange.value); return { action: { const instanceUUID = state.instanceInfo?.uuid; const valueType = state.classInfo?.properties.find((property) => property.name == propertyName)?.valueType; - if (!instanceUUID || !valueType) { + const className = state.classInfo?.name + if (!instanceUUID || !valueType || !className) { return; } - const propertyFqName = `${state.classInfo?.name}.${propertyName}`; - const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(instanceUUID, propertyFqName, value, valueType); + const event = new BackInTimeDebuggerEvent.ForceSetPropertyValue(instanceUUID, className, propertyName, value); dispatch(appActions.forceSetPropertyValue(event)); }} onEditAndEmitValue={(propertyName: string, value: string) => { diff --git a/backintime-flipper-plugin/src/view/sidebar/property_inspector/PropertyInspectorStateSelector.tsx b/backintime-flipper-plugin/src/view/sidebar/property_inspector/PropertyInspectorStateSelector.tsx index 566da788..64d65ff5 100644 --- a/backintime-flipper-plugin/src/view/sidebar/property_inspector/PropertyInspectorStateSelector.tsx +++ b/backintime-flipper-plugin/src/view/sidebar/property_inspector/PropertyInspectorStateSelector.tsx @@ -13,13 +13,13 @@ export const propertyInspectorStateSelector = createSelector( const valueChanges = methodCallInfoList.filter((info) => // FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class. - info.instanceUUID == state.instanceUUID && info.valueChanges.some((change) => change.propertyFqName.split(".").pop() == state.propertyName) + info.instanceUUID == state.instanceUUID && info.valueChanges.some((change) => change.propertyName.split(".").pop() == state.propertyName) ).map((info) => { return { methodCallUUID: info.callUUID, time: info.calledAt, // FIXME: will not work correctly for the class which has a back-in-time debuggable class as a super class. - value: [...info.valueChanges].reverse().find((change) => change.propertyFqName.split(".").pop() == state.propertyName)?.value ?? "", + value: [...info.valueChanges].reverse().find((change) => change.propertyName.split(".").pop() == state.propertyName)?.value ?? "", } }); From 04049b54f308ad0c0c49d3e2572bc4a9ade5703a Mon Sep 17 00:00:00 2001 From: kitakkun <48154936+kitakkun@users.noreply.github.com> Date: Sat, 6 Jul 2024 20:03:05 +0900 Subject: [PATCH 9/9] fix test --- backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx index 8049f2a4..df727f21 100644 --- a/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx +++ b/backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx @@ -114,12 +114,14 @@ test(`notifyValueChange event`, () => { } as NotifyValueChange); expect(store.getState().app.methodCallInfoList[0]).toEqual({ + ownerClassFqName: "com.example.MyClass", instanceUUID: instanceUUID, methodName: "hoge", callUUID: methodCallUUID, calledAt: calledAt, valueChanges: [ { + ownerClassFqName: "com.example.MyClass", propertyName: "hoge", value: "fuga", }