forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalias_type.go
59 lines (50 loc) · 1.34 KB
/
alias_type.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
package typing
import (
"github.com/progrium/darwinkit/generate/modules"
"github.com/progrium/darwinkit/internal/set"
)
var _ Type = (*AliasType)(nil)
// AliasType type def types
type AliasType struct {
Type Type // the real type
GName string // alias name for new go type
Name string // the objc name
Module *modules.Module // used when Alias is not empty
}
func (a *AliasType) GoImports() set.Set[string] {
var imports = set.New[string]()
if a.Module != nil {
imports.Add("github.com/progrium/darwinkit/macos/" + a.Module.Package)
}
imports.AddSet(a.Type.GoImports())
return imports
}
func (a *AliasType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
mod := *a.Module
if currentModule.Package == "appkit" && mod.Package == "uikit" {
mod = *currentModule
}
return FullGoName(mod, a.GName, *currentModule)
}
func (a *AliasType) ObjcName() string {
return a.Name
}
func (a *AliasType) DeclareModule() *modules.Module {
return a.Module
}
// struct alias use go type alias, do not need conversion
func (a *AliasType) isStructAlias() bool {
_, ok := a.Type.(*StructType)
return ok
}
// UnwrapAlias unwrap alias type to it's real underlying type
func UnwrapAlias(t Type) Type {
for true {
at, ok := t.(*AliasType)
if !ok {
return t
}
t = at.Type
}
panic("should not happen")
}