Skip to content

Commit

Permalink
Merge pull request #115 from kitakkun/feature/pass_class_and_property…
Browse files Browse the repository at this point in the history
…_separately

Pass classFqName and propertyName instead of propertyFqName for simplicity
  • Loading branch information
kitakkun authored Jul 6, 2024
2 parents 9cbd1ce + 04049b5 commit 62dfb3b
Show file tree
Hide file tree
Showing 41 changed files with 445 additions and 290 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/review.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion backintime-flipper-plugin/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ node_modules
dist/
.idea/*
!.idea/codeStyles
*.tgz
*.tgz
*.map
5 changes: 3 additions & 2 deletions backintime-flipper-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -65,8 +66,8 @@
"@mui/material": "^5.14.18",
"@reduxjs/toolkit": "^1.9.7",
"@textea/json-viewer": "^3.2.3",
"backintime-websocket-event": "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"
}
}
2 changes: 1 addition & 1 deletion backintime-flipper-plugin/src/BackInTimePlugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<IncomingEvents, OutgoingEvents>) => {
Expand Down
12 changes: 9 additions & 3 deletions backintime-flipper-plugin/src/__tests__/test.incomingEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -97,26 +99,30 @@ test(`notifyValueChange event`, () => {

sendEvent("notifyMethodCall", {
methodName: "hoge",
ownerClassFqName: "com.example.MyClass",
instanceUUID: instanceUUID,
methodCallUUID: methodCallUUID,
calledAt: calledAt,
} as NotifyMethodCall);

sendEvent("notifyValueChange", {
instanceUUID: instanceUUID,
propertyFqName: "hoge",
ownerClassFqName: "com.example.MyClass",
propertyName: "hoge",
value: "fuga",
methodCallUUID: methodCallUUID,
} as NotifyValueChange);

expect(store.getState().app.methodCallInfoList[0]).toEqual({
ownerClassFqName: "com.example.MyClass",
instanceUUID: instanceUUID,
methodName: "hoge",
callUUID: methodCallUUID,
calledAt: calledAt,
valueChanges: [
{
propertyFqName: "hoge",
ownerClassFqName: "com.example.MyClass",
propertyName: "hoge",
value: "fuga",
}
],
Expand Down
4 changes: 3 additions & 1 deletion backintime-flipper-plugin/src/data/MethodCallInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface MethodCallInfo {
ownerClassFqName: string;
callUUID: string;
instanceUUID: string;
methodName: string;
Expand All @@ -7,6 +8,7 @@ export interface MethodCallInfo {
}

export interface ValueChangeInfo {
propertyFqName: string;
ownerClassFqName: string;
propertyName: string;
value: string;
}
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
6 changes: 4 additions & 2 deletions backintime-flipper-plugin/src/reducer/appReducer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -85,6 +85,7 @@ const appSlice = createSlice({
registerMethodCall: (state, action: PayloadAction<BackInTimeDebugServiceEvent.NotifyMethodCall>) => {
const event = action.payload;
state.methodCallInfoList.push({
ownerClassFqName: event.ownerClassFqName,
callUUID: event.methodCallUUID,
instanceUUID: event.instanceUUID,
methodName: event.methodName,
Expand All @@ -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,
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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));
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export const editAndEmitValueStateSelector = createSelector(
return {
...state,
valueType: valueType,
ownerClassFqName: classInfo?.name,
} as EditAndEmitState;
}
);
);
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface EditAndEmitState {
editingValue: any;
open: boolean;
instanceUUID: string;
ownerClassFqName: string;
propertyName: string;
valueType: string | undefined;
}
Expand All @@ -34,4 +35,4 @@ export function EditAndEmitValueView({state, onEdit}: EditAndEmitValueViewProps)
</Layout.Container>
</Layout.Horizontal>
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: <EmitButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -29,11 +29,11 @@ export function ValueEmitModalPage() {
onValueEmit={(propertyName: string, value: string) => {
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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?? "",
}
});

Expand Down
15 changes: 10 additions & 5 deletions backintime-flipper-plugin/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -3312,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"
Expand Down Expand Up @@ -5909,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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
},
)
Expand Down
Loading

0 comments on commit 62dfb3b

Please sign in to comment.