-
Notifications
You must be signed in to change notification settings - Fork 19
/
kotlin.go
89 lines (72 loc) · 1.9 KB
/
kotlin.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package gazelle
import (
"path"
"strings"
)
import "github.com/emirpasic/gods/sets/treeset"
import (
jvm_java "github.com/bazel-contrib/rules_jvm/java/gazelle/private/java"
jvm_types "github.com/bazel-contrib/rules_jvm/java/gazelle/private/types"
)
func IsNativeImport(impt string) bool {
if strings.HasPrefix(impt, "kotlin.") || strings.HasPrefix(impt, "kotlinx.") {
return true
}
jvm_import := jvm_types.NewPackageName(impt)
// Java native/standard libraries
if jvm_java.IsStdlib(jvm_import) {
return true
}
return false
}
type KotlinTarget struct {
Imports *treeset.Set
}
/**
* Information for kotlin library target including:
* - kotlin files
* - kotlin import statements from all files
* - kotlin packages implemented
*/
type KotlinLibTarget struct {
KotlinTarget
Packages *treeset.Set
Files *treeset.Set
}
func NewKotlinLibTarget() *KotlinLibTarget {
return &KotlinLibTarget{
KotlinTarget: KotlinTarget{
Imports: treeset.NewWith(importStatementComparator),
},
Packages: treeset.NewWithStringComparator(),
Files: treeset.NewWithStringComparator(),
}
}
/**
* Information for kotlin binary (main() method) including:
* - kotlin import statements from all files
* - the package
* - the file
*/
type KotlinBinTarget struct {
KotlinTarget
File string
Package string
}
func NewKotlinBinTarget(file, pkg string) *KotlinBinTarget {
return &KotlinBinTarget{
KotlinTarget: KotlinTarget{
Imports: treeset.NewWith(importStatementComparator),
},
File: file,
Package: pkg,
}
}
// packagesKey is the name of a private attribute set on generated kt_library
// rules. This attribute contains the KotlinTarget for the target.
const packagesKey = "_kotlin_package"
func toBinaryTargetName(mainFile string) string {
base := strings.ToLower(strings.TrimSuffix(path.Base(mainFile), path.Ext(mainFile)))
// TODO: move target name template to directive
return base + "_bin"
}