This repository has been archived by the owner on Apr 20, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautofill.py
70 lines (62 loc) · 2.9 KB
/
autofill.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
60
61
62
63
64
65
66
67
68
69
70
import json
import pprint
from common import *
prefix = '/home/sam/sandbox/NullSafetyJava-master/nullaway-eval/repos/'
def index(repo, checker):
mapping = {}
with open('{}/{}.txt'.format(repo, checker)) as file:
current = None
span = []
for line in file:
if line.isspace():
if current:
mapping[current] = span
current = None
span = []
if line.startswith(prefix):
span = []
colon = find_nth(line, ':', 2)
current = line[len(prefix)+len(repo)+1:colon]
span.append(line)
return mapping
indices = {}
for repo in repos:
indices[repo] = {}
for checker in checkers.keys():
indices[repo][checker] = index(repo, checker)
with open('disagreement.json') as file:
data = json.load(file)
appraisals = {}
for repo, groups in data.items():
for type, checks in groups.items():
for checker, messages in checks.items():
for line, appraisal in messages.items():
if not appraisal:
if ((type == 'present' and checker == 'eradicate') or (type == 'missing' and checker != 'eradicate')) and line in indices[repo]['eradicate']:
message = indices[repo]['eradicate'][line]
if 'test' in line.lower():
appraisals[line] = 'eradicate test'
elif 'ERADICATE_PARAMETER_NOT_NULLABLE' in message[0]:
appraisals[line] = 'eradicate parameter'
elif 'ERADICATE_INCONSISTENT_SUBCLASS_PARAMETER_ANNOTATION' in message[0]:
appraisals[line] = 'eradicate override'
elif 'ERADICATE_FIELD_NOT_INITIALIZED' in message[0]:
appraisals[line] = 'unstrict field'
elif 'ERADICATE_FIELD_NOT_NULLABLE' in message[0]:
appraisals[line] = 'missing annotation'
elif 'ERADICATE_RETURN_NOT_NULLABLE' in message[0]:
appraisals[line] = 'missing annotation'
elif ((type == 'present' and checker == 'nullsafe') or (type == 'missing' and checker != 'eradicate')) and line in indices[repo]['nullsafe']:
message = indices[repo]['nullsafe'][line]
if 'NULLSAFE_FIELD_NOT_NULLABLE' in message[0]:
appraisals[line] = 'missing annotation'
with open('disagreement.json') as input:
for line in input:
if '""' in line:
first_quote = find_nth(line, '"', 1)
second_quote = find_nth(line, '"', 2)
key = line[first_quote+1:second_quote]
if key in appraisals:
print(line.replace('""', '"'+appraisals[key]+'"'),end='')
continue
print(line, end='')