-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatementcount.py
More file actions
32 lines (27 loc) · 1.13 KB
/
Copy pathstatementcount.py
File metadata and controls
32 lines (27 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# Copyright (C) 2011 XiaoyanZhu
# Authors : Xiaoyan Zhu <xyxyzh@gmail.com>
import os,re
import string
def count_statement(file_path,num_hunk):
r = [0 for i in range(0,19)]
statements = ["call","if","for","while","do","switch","case","continue",
"break","return","else","function","function_decl","decl_stmt",
"constructor","try","catch","throw"]
diff = hunk_source_to_xml(file_path,num_hunk)
leng = len(statements)
for i in range(0,leng):
statement = statements[i]
r[i] = string.count(diff,"<"+statement+">") + string.count(diff,"/"+statement+"[")
return r
def hunk_source_to_xml(file_path,num_hunk):
diff = ""
for i in range(1,num_hunk):
file_name = file_path + str(i)
os.system(file_path+"src2srcml -l Java "+file_name+"_old.java -o "+file_name+"_old.xml")
os.system(file_path+"src2srcml -l Java "+file_name+"_new.java -o "+file_name+"_new.xml")
diff += compare_xml(file_name)
return diff
def compare_xml(file_name):
diff = os.popen("xmldiff "+file_name+"_old.xml "+file_name+"_new.xml").read()
return diff