-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgumtreeAST.py
59 lines (52 loc) · 2.5 KB
/
gumtreeAST.py
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import json
from tqdm import tqdm
import glob
import subprocess
import os
import numpy as np
import json
def gptastdiff(way, gumtree_path):
sum=0
kk = []
list_number=[]
pros = ['Chart','Lang','Time','Mockito','Math','Closure','Cli','Codec','Csv','Gson','JacksonCore','Jsoup']
pro_nums = [26,65,27,38,106,133,40,18,16,18,26,93]
for project,nums in zip(pros,pro_nums):
for i in range(nums):
mutant_file = '%s/mutant_filter/%s/%s_%s_test.json' % (way, project, project, i+1)
with open(mutant_file,"r",encoding="utf-8") as f:
mutant = json.load(f)
print(mutant_file)
for m in mutant:
d4j_fix_path = m['filepath']
try:
lines1 = open(d4j_fix_path, "r",errors='ignore').read().strip()
liness = lines1.splitlines()
liness[m['line']-1]=m['aftercode']
after_mutant_path = f'{way}.java'
with open(after_mutant_path, "w") as file:
file.write('\n'.join(liness))
cmd="java -cp %s/target/gumtree-spoon-ast-diff-SNAPSHOT.jar:%s/target/gumtree-spoon-ast-diff-SNAPSHOT-jar-with-dependencies.jar gumtree.spoon.AstComparator %s %s"%(gumtree_path,gumtree_path, d4j_fix_path,after_mutant_path)
log=subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, bufsize=-1, start_new_session=True)
stdout, stderr = log.communicate()
#print(log.returncode)
if log.returncode != 0:
continue
output = stdout.decode('utf-8')
number = output.count('\n\t')
list_number.append({'ast':number, 'line':m['line'],'filepath':d4j_fix_path, 'precode':m['precode'],'aftercode':m['aftercode']})
except Exception as e:
print(d4j_fix_path, "failed")
continue
list_number = sorted(list_number,key=lambda x:x['ast'])
savepath = f'gumAST/{way}.json'
if not os.path.exists('gumAST'):
os.makedirs('gumAST')
with open(savepath, 'w', encoding='utf-8') as file1:
json.dump(list_number, file1, ensure_ascii=False,indent=4)
way = 'Deepseek'
gumtree_path = 'your own path'
gptastdiff(way, gumtree_path)
# ways = ['Deepseek', 'Codellama', 'Gpt/gpt3.5', 'Gpt/gpt4o', 'Gpt/gpt4omini', 'Leam', 'Major', 'Starchat']
# for way in ways:
# gptastdiff(way, gumtree_path)