forked from progrium/darwinkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprotocol_type.go
50 lines (40 loc) · 1.22 KB
/
protocol_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
package typing
import (
"github.com/progrium/macdriver/generate/modules"
"github.com/progrium/macdriver/internal/set"
)
var _ Type = (*ProtocolType)(nil)
// ProtocolType objective-c protocol type
type ProtocolType struct {
Name string // the objc type name
GName string // Go name, usually is objc type name without prefix 'NS'
Module *modules.Module // object-c module name
}
func (p *ProtocolType) GoName(currentModule *modules.Module, receiveFromObjc bool) string {
if receiveFromObjc {
return FullGoName(*p.Module, p.GoWrapperName(), *currentModule)
} else {
return FullGoName(*p.Module, p.GoInterfaceName(), *currentModule)
}
}
func (p *ProtocolType) ObjcName() string {
return "id<" + p.Name + ">"
}
func (p *ProtocolType) GoImports() set.Set[string] {
return set.New("github.com/progrium/macdriver/objc", "github.com/progrium/macdriver/macos/"+p.Module.Package)
}
func (p *ProtocolType) DeclareModule() *modules.Module {
return p.Module
}
func (p *ProtocolType) GoInterfaceName() string {
return "P" + p.GName
}
func (p *ProtocolType) GoStructName() string {
return p.GName
}
func (p *ProtocolType) GoWrapperName() string {
if p.GName == "Object" {
return p.GName
}
return p.GName + "Object"
}