Skip to content

Commit 492af96

Browse files
committed
Sort package imports in codegen
Signed-off-by: James Hamlin <jfhamlin@gmail.com>
1 parent 989821e commit 492af96

7 files changed

Lines changed: 185 additions & 336 deletions

File tree

pkg/codegen/TODO.txt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,25 @@
33
- handle namespace requires/uses/etc.
44
- handle let bindings that are shared across multiple vars
55
- test repeated let bindings of the same name, where previous bindings are shadowed
6+
7+
8+
Handle
9+
- java.io.StringReader21 "java.io.StringReader"
10+
- Exception12 "Exception"
11+
- java.lang.annotation17 "java.lang.annotation"
12+
- LinkedBlockingQueue28 "LinkedBlockingQueue"
13+
- CompilerException29 "glojure.lang.Compiler/CompilerException"
14+
- BigInteger11 "BigInteger"
15+
- java.lang.UnsupportedOperationException14 "java.lang.UnsupportedOperationException"
16+
- ExceptionInfo15 "ExceptionInfo"
17+
- lang1 "github.com/glojurelang/glojure/pkg/lang"
18+
- java.lang6 "java.lang"
19+
- glojure.lang.LineNumberingPushbackReader19 "glojure.lang.LineNumberingPushbackReader"
20+
- java.util.concurrent.CountDownLatch25 "java.util.concurrent.CountDownLatch"
21+
- BigDecimal9 "BigDecimal"
22+
- java.util.concurrent8 "java.util.concurrent"
23+
- java.io.InputStreamReader20 "java.io.InputStreamReader"
24+
- java.util22 "java.util"
25+
- glojure.lang4 "glojure.lang"
26+
- Object16 "Object"
27+
- java.net30 "java.net"

pkg/codegen/codegen.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,17 @@ import (
12881288
"github.com/glojurelang/glojure/pkg/lang"
12891289
`
12901290

1291-
for pkg, alias := range g.imports {
1291+
// sort the imports by their package name for deterministic output
1292+
keys := make([]string, 0, len(g.imports))
1293+
for k := range g.imports {
1294+
keys = append(keys, k)
1295+
}
1296+
sort.Slice(keys, func(i, j int) bool {
1297+
return g.imports[keys[i]] < g.imports[keys[j]]
1298+
})
1299+
1300+
for _, pkg := range keys {
1301+
alias := g.imports[pkg]
12921302
header += fmt.Sprintf(" %s \"%s\"\n", alias, pkg)
12931303
}
12941304

0 commit comments

Comments
 (0)