forked from moezbhatti/qksms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_nullable_views.py
More file actions
40 lines (32 loc) · 1.24 KB
/
fix_nullable_views.py
File metadata and controls
40 lines (32 loc) · 1.24 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
33
34
35
36
37
38
39
40
#!/usr/bin/env python3
"""Fix nullable types in migrated view properties."""
import re, os
src_dir = "presentation/src"
count = 0
for root, dirs, files in os.walk(src_dir):
for f in files:
if not f.endswith('.kt'):
continue
filepath = os.path.join(root, f)
with open(filepath) as fh:
content = fh.read()
if '// View references (migrated from synthetics)' not in content:
continue
original = content
# Fix Activity/Widget/Dialog pattern: Type? get() = findViewById(R.id.xxx)
content = re.sub(
r'(private val \w+): (\w+)\? get\(\) = findViewById\(R\.id\.(\w+)\)',
r'\1: \2 get() = findViewById(R.id.\3)',
content
)
# Fix Controller pattern: Type? get() = view?.findViewById(R.id.xxx)
content = re.sub(
r'(private val \w+): (\w+)\? get\(\) = view\?\.findViewById\(R\.id\.(\w+)\)',
r'\1: \2 get() = view!!.findViewById(R.id.\3)',
content
)
if content != original:
with open(filepath, 'w') as fh:
fh.write(content)
count += 1
print(f"Fixed nullable types in {count} files")