Skip to content

Commit 89b4fcd

Browse files
Sahar MehrpourSahar Mehrpour
authored andcommitted
expressions and declarations are working
1 parent 08db0f7 commit 89b4fcd

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

src/FileChangeManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,21 @@ void processReceivedMessages(JsonObject messageAsJson) {
272272

273273
break;
274274

275+
276+
case "EXPR_STMT":
277+
String exprText = messageAsJson.get("data").getAsString();
278+
String resultExprXml = SRCMLHandler.createXMLForText(exprText, projectPath + "/tempExprDeclFile.java");
279+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "EXPR_STMT_XML", resultExprXml}).toString());
280+
281+
break;
282+
283+
case "DECL_STMT":
284+
String declText = messageAsJson.get("data").getAsString();
285+
String resultDeclXml = SRCMLHandler.createXMLForText(declText, projectPath + "/tempExprDeclFile.java");
286+
s.sendToAll(MessageProcessor.encodeData(new Object[]{"IDEA", "WEB", "DECL_STMT_XML", resultDeclXml}).toString());
287+
288+
break;
289+
275290
case "NEW_RULE":
276291

277292
//TODO first add the rule, then write it in the file

src/core/model/SRCMLHandler.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.io.BufferedReader;
88
import java.io.IOException;
99
import java.io.InputStreamReader;
10+
import java.io.PrintWriter;
1011

1112
public class SRCMLHandler {
1213

@@ -144,4 +145,26 @@ public static int findLineNumber(String fullPath) {
144145
}
145146

146147

148+
/**
149+
* create an xml string for a given piece of code
150+
*
151+
* @param exprText a piece of code
152+
* @param filePath the path of the temp file
153+
* @return xml string
154+
*/
155+
public static String createXMLForText(String exprText, String filePath) {
156+
157+
// create a file and write the string into that
158+
try {
159+
PrintWriter writer = new PrintWriter(filePath, "UTF-8");
160+
writer.println(exprText);
161+
writer.close();
162+
} catch (IOException e) {
163+
System.out.println("error in writing the result xml");
164+
return "";
165+
}
166+
167+
// create the srcml xml string and return the string
168+
return createXMLForFile(filePath);
169+
}
147170
}

src/utilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static boolean isFileAChildOf(VirtualFile maybeChild, VirtualFile possibleParent
3333
static List<VirtualFile> createIgnoredFileList(Project project) {
3434
List<VirtualFile> ignoredFiles = new ArrayList<>();
3535
List<String> files = new ArrayList<>(Arrays.asList(".idea", "out", "source_xml.xml", "tempResultXmlFile.xml",
36-
"testProject.iml", ".DS_Store", "bin", "build", "node_modules", ".setting", ".git", "war"));
36+
"testProject.iml", ".DS_Store", "bin", "build", "node_modules", ".setting", ".git", "war", "tempExprDeclFile.java"));
3737
for (String f : files) {
3838
VirtualFile vfile = project.getBaseDir().findFileByRelativePath(f);
3939

0 commit comments

Comments
 (0)