-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_option.go
More file actions
66 lines (58 loc) · 1.7 KB
/
gen_option.go
File metadata and controls
66 lines (58 loc) · 1.7 KB
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
package codegen
import "github.com/AndroidGoLab/binder/tools/pkg/resolver"
// GenOption configures code generation.
type GenOption func(*GenOptions)
// WithRegistry sets the type registry for looking up type definitions
// during code generation. This enables correct marshaling of enum types
// (as integers) and interface types (as IBinder).
func WithRegistry(
registry *resolver.TypeRegistry,
) GenOption {
return func(opts *GenOptions) {
opts.Registry = registry
}
}
// WithCurrentPkg sets the AIDL package of the type being generated.
// This enables cross-package type references to be qualified correctly.
func WithCurrentPkg(
pkg string,
) GenOption {
return func(opts *GenOptions) {
opts.CurrentPkg = pkg
}
}
// WithImportGraph sets the import graph for cycle detection.
// When set, cross-package type references that would create import
// cycles are replaced with any to break the cycle.
func WithImportGraph(
graph *ImportGraph,
) GenOption {
return func(opts *GenOptions) {
opts.ImportGraph = graph
}
}
// WithCurrentDef sets the fully qualified name of the definition being
// generated (e.g., "android.hardware.bluetooth.audio.CodecId"). This enables
// nested type references like "A2dp" to resolve to "CodecId.A2dp" first.
func WithCurrentDef(
def string,
) GenOption {
return func(opts *GenOptions) {
opts.CurrentDef = def
}
}
// WithCycleTypeCallback sets a callback for types redirected to sub-packages.
func WithCycleTypeCallback(
cb func(qualifiedName, typesPkg string),
) GenOption {
return func(opts *GenOptions) {
opts.CycleTypeCallback = cb
}
}
func applyGenOptions(options []GenOption) GenOptions {
var opts GenOptions
for _, o := range options {
o(&opts)
}
return opts
}