Skip to content

Commit

Permalink
Merge pull request #61 from devuxd/AddNewCommand
Browse files Browse the repository at this point in the history
added a new websocket command
  • Loading branch information
SaharMehrpour authored May 22, 2024
2 parents 113d181 + 2beaa64 commit 05c262d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/core/coreConstants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
23 changes: 23 additions & 0 deletions src/core/utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class Utilities {
*/
static sendToServer(ws, command, data) {
let messageJson = {command: command};
let secondMessageJson = null;

if (ws) {
switch (command) {
Expand All @@ -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:
Expand Down Expand Up @@ -88,6 +96,8 @@ class Utilities {
}

ws.send(JSON.stringify(messageJson));
if (secondMessageJson)
ws.send(JSON.stringify(secondMessageJson))
}
}

Expand Down Expand Up @@ -219,6 +229,19 @@ class Utilities {
return indices;
}

static removeSrcmlAnnotations(xmlString) {
// removes srcml tags
xmlString = xmlString.replace(/<[^>]*>/g, "");
// replaces &lt; with <
xmlString = xmlString.replace(/&lt;/g, "<");
// replaces &gt; with >
xmlString = xmlString.replace(/&gt;/g, ">");
// replaces &amp; with &
xmlString = xmlString.replace(/&amp;/g, "&");

return xmlString;
}

}

export default Utilities;
17 changes: 2 additions & 15 deletions src/ui/rulePanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,28 +505,15 @@ class SnippetView extends Component {
};
}

removeAnnotations(xmlString) {
// removes srcml tags
xmlString = xmlString.replace(/<[^>]*>/g, "");
// replaces &lt; with <
xmlString = xmlString.replace(/&lt;/g, "<");
// replaces &gt; with >
xmlString = xmlString.replace(/&gt;/g, ">");
// replaces &amp; with &
xmlString = xmlString.replace(/&amp;/g, "&");

return xmlString;
}

handleSuggestion = async (
rule,
example,
snippet,
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(
Expand Down

0 comments on commit 05c262d

Please sign in to comment.