From 470810086e777ae3f425e3dcbe3530b463225df6 Mon Sep 17 00:00:00 2001 From: racoelhosilva Date: Tue, 23 Jul 2024 17:31:55 +0100 Subject: [PATCH 1/2] feat: integrated event system on Joinpoints.ts generation --- Lara-JS/scripts/build-interfaces.js | 4 +++- Lara-JS/scripts/generate-ts-joinpoints.js | 19 +++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Lara-JS/scripts/build-interfaces.js b/Lara-JS/scripts/build-interfaces.js index bde9da775..44268eb58 100755 --- a/Lara-JS/scripts/build-interfaces.js +++ b/Lara-JS/scripts/build-interfaces.js @@ -61,7 +61,9 @@ import { registerJoinpointMapper, wrapJoinPoint, unwrapJoinPoint, -} from "lara-js/api/LaraJoinPoint.js";\n\n` +} from "lara-js/api/LaraJoinPoint.js"; +import eventListener from "./clava/history/EventListener.js"; +import { Event, EventTime } from "./clava/history/Events.js";\n\n` ); generateDefaultAttributeMappers(specification.joinpoints, outputFile); diff --git a/Lara-JS/scripts/generate-ts-joinpoints.js b/Lara-JS/scripts/generate-ts-joinpoints.js index 155711095..213d0c707 100644 --- a/Lara-JS/scripts/generate-ts-joinpoints.js +++ b/Lara-JS/scripts/generate-ts-joinpoints.js @@ -166,13 +166,28 @@ function generateJoinpointAction(action, outputFile, joinpoints) { ) .join(", "); + const eventParameters = action.parameters + .map((parameter) => parameter.name.split(":")[0]) + .join(", "); + fs.writeSync( outputFile, `${generateDocumentation(action.tooltip)} ${action.name}(${parameters}): ${ action.returnType - } { return wrapJoinPoint(this._javaObject.${ + } { + eventListener.emit("ACTION", new Event(EventTime.BEFORE, "${ + action.name + }", this, undefined${ + eventParameters.length > 0 ? `, ${eventParameters}` : "" + })); + const res = wrapJoinPoint(this._javaObject.${ action.name - }(${callParameters})); }\n` + }(${callParameters})); + eventListener.emit("ACTION", new Event(EventTime.AFTER, "${ + action.name + }", this, res${eventParameters.length > 0 ? `, ${eventParameters}` : ""})); + return res; + }\n` ); } From 9c66c4d672d0a0c6553cde8e8d1278530d6ad093 Mon Sep 17 00:00:00 2001 From: racoelhosilva Date: Fri, 26 Jul 2024 11:43:15 +0100 Subject: [PATCH 2/2] fix: changed the Event import path --- Lara-JS/scripts/build-interfaces.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lara-JS/scripts/build-interfaces.js b/Lara-JS/scripts/build-interfaces.js index 44268eb58..b4e7acd79 100755 --- a/Lara-JS/scripts/build-interfaces.js +++ b/Lara-JS/scripts/build-interfaces.js @@ -62,8 +62,8 @@ import { wrapJoinPoint, unwrapJoinPoint, } from "lara-js/api/LaraJoinPoint.js"; -import eventListener from "./clava/history/EventListener.js"; -import { Event, EventTime } from "./clava/history/Events.js";\n\n` +import eventListener from "./clava/events/EventListener.js"; +import { Event, EventTime } from "./clava/events/Events.js";\n\n` ); generateDefaultAttributeMappers(specification.joinpoints, outputFile);