From 2beaa6412e42abb60a82038305494f8841eda701 Mon Sep 17 00:00:00 2001 From: saharmehrpour Date: Tue, 14 May 2024 13:35:29 -0400 Subject: [PATCH] added a new command --- src/core/coreConstants.js | 1 + src/core/utilities.js | 23 +++++++++++++++++++++++ src/ui/rulePanel.js | 17 ++--------------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/core/coreConstants.js b/src/core/coreConstants.js index bb6e13a..2817b0d 100644 --- a/src/core/coreConstants.js +++ b/src/core/coreConstants.js @@ -2,6 +2,7 @@ export const webSocketSendMessage = { modified_rule_msg: "MODIFIED_RULE", modified_tag_msg: "MODIFIED_TAG", snippet_xml_msg: "XML_RESULT", + converted_java_snippet_msg: "CONVERTED_JAVA_SNIPPET", code_to_xml_msg: "EXPR_STMT", new_rule_msg: "NEW_RULE", new_tag_msg: "NEW_TAG", diff --git a/src/core/utilities.js b/src/core/utilities.js index 2256f22..2cec4a1 100644 --- a/src/core/utilities.js +++ b/src/core/utilities.js @@ -14,6 +14,7 @@ class Utilities { */ static sendToServer(ws, command, data) { let messageJson = {command: command}; + let secondMessageJson = null; if (ws) { switch (command) { @@ -34,6 +35,13 @@ class Utilities { fileName: data.fileName, xml: data.xml }; + secondMessageJson = { + command: webSocketSendMessage.converted_java_snippet_msg, + data: { + fileName: data.fileName, + convertedJava: Utilities.removeSrcmlAnnotations(data.xml) + } + }; break; case webSocketSendMessage.code_to_xml_msg: @@ -88,6 +96,8 @@ class Utilities { } ws.send(JSON.stringify(messageJson)); + if (secondMessageJson) + ws.send(JSON.stringify(secondMessageJson)) } } @@ -219,6 +229,19 @@ class Utilities { return indices; } + static removeSrcmlAnnotations(xmlString) { + // removes srcml tags + xmlString = xmlString.replace(/<[^>]*>/g, ""); + // replaces < with < + xmlString = xmlString.replace(/</g, "<"); + // replaces > with > + xmlString = xmlString.replace(/>/g, ">"); + // replaces & with & + xmlString = xmlString.replace(/&/g, "&"); + + return xmlString; + } + } export default Utilities; \ No newline at end of file diff --git a/src/ui/rulePanel.js b/src/ui/rulePanel.js index 5f0a4d9..f275c38 100644 --- a/src/ui/rulePanel.js +++ b/src/ui/rulePanel.js @@ -505,19 +505,6 @@ class SnippetView extends Component { }; } - removeAnnotations(xmlString) { - // removes srcml tags - xmlString = xmlString.replace(/<[^>]*>/g, ""); - // replaces < with < - xmlString = xmlString.replace(/</g, "<"); - // replaces > with > - xmlString = xmlString.replace(/>/g, ">"); - // replaces & with & - xmlString = xmlString.replace(/&/g, "&"); - - return xmlString; - } - handleSuggestion = async ( rule, example, @@ -525,8 +512,8 @@ class SnippetView extends Component { exampleFilePath, violationFilePath, ) => { - const parsedSnippet = this.removeAnnotations(snippet); - const parsedExample = this.removeAnnotations(example); + const parsedSnippet = Utilities.removeSrcmlAnnotations(snippet); + const parsedExample = Utilities.removeSrcmlAnnotations(example); // prevent multiple calls to suggestFix if (!this.state.suggestionCreated) { suggestFix(