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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
//! JNI adapter metadata propagated through `TypeEntry`.
use KtType;
/// How a `Shape::Optional` fold layer represents `None` over the JNI wire —
/// the per-layer payload `N` of the JNI adapter's [`FoldStrategy`].
///
/// The choice is made at the point the `Option<_>` wrapper folds the layer onto
/// a projection's `FoldStrategy`, and only depends on whether `option_output`
/// rode the inner converter's niche (wire stayed identical to the inner's wire)
/// or boxed the primitive into `java.lang.<Box>` (wire widened to `JObject`).
/// The renderer reads this to pick the matching Kotlin shape — without it, a
/// primitive-wired `Option<Handle>` would be declared as nullable `Long?` even
/// though the wire is a non-nullable `jlong` whose `0L` *is* the null.
/// The JNI adapter's nullability / collection layer stack over a projection
/// leaf, on the unified [`Shape`](prebindgen_registry::shape::Shape)
/// with [`NullableKind`] as the per-`Optional`-layer payload:
/// * `Base` — the receiver *is* the handle;
/// * `Optional(kind, inner)` — `T?`; `kind` records how null is represented
/// over the wire (see [`NullableKind`]);
/// * `Iterable(inner)` — `List<T>`. EXTENSION POINT: no `Vec<Handle>` shape
/// exists today, so the emitters guard this arm loudly rather than silently
/// mis-generating.
pub type FoldStrategy = Shape;
/// Which flavor of Kotlin newtype a [`Projection`] surfaces. Both share the
/// same "wire != declared Kotlin type, wrap as `W(wire)`, fold through
/// `Option`/`Vec`" shape; they differ only in how a struct field stores them
/// and whether they own a closeable resource.
/// Folded description of a Kotlin newtype projection (opaque handle or
/// `ULong`) reached through zero or more wrapper layers. Set at the leaf,
/// transformed by each wrapper as the type folds (see [`FoldStrategy`]), and
/// read by every typed-surface emitter (data-class fields, struct
/// encode/decode, `classify_return`, param classification) so "what Kotlin
/// class does this surface, how do I wrap/fold it, do I close it" has one
/// source of truth instead of a parallel ad-hoc decision tree.
/// Per-converter language-specific extras carried by every converter this
/// adapter produces. Filled by the same handler that builds the wire/body,
/// propagated by the resolver into
/// [`prebindgen_registry::TypeEntry::metadata`], and read directly by
/// the Kotlin emitter — so cross-language facts flow through the existing
/// wrapper machinery rather than a parallel side channel.