-
Notifications
You must be signed in to change notification settings - Fork 2
/
gen_fix_override.go
71 lines (57 loc) · 1.44 KB
/
gen_fix_override.go
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
71
// +build ignore
package main
import (
"bytes"
"io/ioutil"
"os/exec"
"strconv"
"strings"
)
func main() {
out, _ := exec.Command("bash", "-c", "swiftc -j8 -continue-building-after-errors -typecheck ./Sources/qt/*").CombinedOutput()
m := make(map[string]map[int]bool)
for _, l := range bytes.Split(out, []byte("\n")) {
if !bytes.Contains(l, []byte(":")) {
continue
}
if !bytes.Contains(l, []byte(" error: ")) {
continue
}
ls := bytes.Split(l, []byte(":"))
file := string(ls[0])
line, _ := strconv.Atoi(string(ls[1]))
line--
if !strings.Contains(file, ".swift") {
continue
}
if _, ok := m[file]; !ok {
m[file] = make(map[int]bool)
}
if bytes.Contains(l, []byte("overriding declaration requires an")) {
m[file][line] = true
} else if bytes.Contains(l, []byte("method does not override any method")) {
m[file][line] = false
} else {
//println(file, line, "=>", string(l))
}
}
for f := range m {
data, err := ioutil.ReadFile(f)
if err != nil {
println("failed to read the file", err.Error())
continue
}
datas := bytes.Split(data, []byte("\n"))
for i, l := range datas {
if _, ok := m[f][i]; !ok {
continue
}
if m[f][i] {
datas[i] = bytes.Replace(l, []byte("public "), []byte("public override "), -1)
} else {
datas[i] = bytes.Replace(l, []byte("public override "), []byte("public "), -1)
}
}
ioutil.WriteFile(f, bytes.Join(datas, []byte("\n")), 0644)
}
}