-
Notifications
You must be signed in to change notification settings - Fork 14
/
propagate_names.py
44 lines (32 loc) · 1.19 KB
/
propagate_names.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
import json
import os
import sys
def propagate_names(diff_path: str, mappings_path: str):
with open(diff_path, 'r') as diff_file:
diff_dict = json.loads(diff_file.read())
for i in os.listdir(mappings_path):
if i == "counter.txt":
continue
with open(mappings_path + "/" + i, 'r') as f:
lines = [transform_line(line, diff_dict) + "\n" for line in f.read().splitlines()]
with open(mappings_path + "/" + i, 'w') as f:
f.writelines(lines)
def transform_line(line: str, dic: dict):
line_parts = line.split("\t")
match line_parts[0]:
case "CLASS":
class_path = line_parts[-1].split("/")
names = class_path[-1].split("$")
names = [transform(key, dic) for key in names]
class_path[-1] = '$'.join(names)
line_parts[-1] = '/'.join(class_path)
case "FIELD" | "METHOD":
line_parts[-1] = transform(line_parts[-1], dic)
return '\t'.join(line_parts)
def transform(key: str, dic: dict):
if (var := dic.get(key)) is not None:
return var
else:
return key
if __name__ == "__main__":
propagate_names(sys.argv[1], sys.argv[2])