forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdict_type.go
43 lines (36 loc) · 1.13 KB
/
dict_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
package typing
import "C"
import (
"github.com/progrium/macdriver/generate/modules"
"github.com/progrium/macdriver/internal/set"
)
var _ Type = (*DictType)(nil)
// DictType for objc Dictionary types, the element should be StringType or ClassType
type DictType struct {
KeyType Type
ValueType Type
}
func (d *DictType) GoImports() set.Set[string] {
var imports = set.New("github.com/progrium/macdriver/macos/foundation")
imports.AddSet(d.KeyType.GoImports())
imports.AddSet(d.ValueType.GoImports())
return imports
}
func (d *DictType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
if _, ok := UnwrapAlias(d.KeyType).(*StringType); ok {
if _, ok = d.ValueType.(*ProtocolType); !ok {
return "map[" + d.KeyType.GoName(currentModule, receiveFromObjc) + "]" + d.ValueType.GoName(currentModule, receiveFromObjc)
}
}
name := "Dictionary"
if !receiveFromObjc {
name = "Dictionary"
}
return FullGoName(*modules.Get("foundation"), name, *currentModule)
}
func (d *DictType) ObjcName() string {
return "NSDictionary*"
}
func (d *DictType) DeclareModule() *modules.Module {
return d.ValueType.DeclareModule()
}