-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathJavaPeerInfo.cs
More file actions
326 lines (278 loc) · 11.2 KB
/
JavaPeerInfo.cs
File metadata and controls
326 lines (278 loc) · 11.2 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
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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
using System;
using System.Collections.Generic;
namespace Microsoft.Android.Sdk.TrimmableTypeMap;
/// <summary>
/// Represents a Java peer type discovered during assembly scanning.
/// Contains all data needed by downstream generators (TypeMap IL, UCO wrappers, JCW Java sources).
/// Generators consume this data model — they never touch PEReader/MetadataReader.
/// </summary>
public sealed record JavaPeerInfo
{
/// <summary>
/// JNI type name, e.g., "android/app/Activity".
/// Extracted from the [Register] attribute or auto-computed during scanning.
/// Manifest rooting may later promote this to <see cref="CompatJniName"/> when
/// a component is referenced by its managed-namespace form.
/// </summary>
public required string JavaName { get; set; }
/// <summary>
/// Compat JNI type name, e.g., "myapp.namespace/MyType" for user types (uses raw namespace, not CRC64).
/// For MCW binding types (with [Register]), this equals <see cref="JavaName"/>.
/// Used by acw-map.txt to support legacy custom view name resolution in layout XMLs.
/// </summary>
public required string CompatJniName { get; init; }
/// <summary>
/// Full managed type name, e.g., "Android.App.Activity".
/// </summary>
public required string ManagedTypeName { get; init; }
/// <summary>
/// Managed type namespace, e.g., "Android.App".
/// </summary>
public required string ManagedTypeNamespace { get; init; }
/// <summary>
/// Managed type short name (without namespace), e.g., "Activity".
/// </summary>
public required string ManagedTypeShortName { get; init; }
/// <summary>
/// Assembly name the type belongs to, e.g., "Mono.Android".
/// </summary>
public required string AssemblyName { get; init; }
/// <summary>
/// JNI name of the base Java type, e.g., "android/app/Activity" for a type
/// that extends Activity. Null for java/lang/Object or types without a Java base.
/// Needed by JCW Java source generation ("extends" clause).
/// </summary>
public string? BaseJavaName { get; set; }
/// <summary>
/// JNI names of Java interfaces this type implements, e.g., ["android/view/View$OnClickListener"].
/// Needed by JCW Java source generation ("implements" clause).
/// </summary>
public IReadOnlyList<string> ImplementedInterfaceJavaNames { get; init; } = Array.Empty<string> ();
public bool IsInterface { get; init; }
public bool IsAbstract { get; init; }
/// <summary>
/// If true, this is a Managed Callable Wrapper (MCW) binding type.
/// No JCW or RegisterNatives will be generated for it.
/// </summary>
public bool DoNotGenerateAcw { get; init; }
/// <summary>
/// Types with component attributes ([Activity], [Service], etc.),
/// custom views from layout XML, or manifest-declared components
/// are unconditionally preserved (not trimmable).
/// May be set to <c>true</c> after scanning when the manifest references a type
/// that the scanner did not mark as unconditional. Should only ever be set
/// to <c>true</c>, never back to <c>false</c>.
/// </summary>
public bool IsUnconditional { get; set; }
/// <summary>
/// True for Application and Instrumentation types, plus any generated managed
/// base classes they rely on during startup. These types cannot call
/// <c>registerNatives</c> in their static initializer because the native library
/// (<c>libmonodroid.so</c>) is not loaded until after the Application class is instantiated.
/// Registration is deferred to <c>ApplicationRegistration.registerApplications()</c>.
/// This may also be set after scanning when a type is only discovered from
/// manifest <c>android:name</c> usage on <c><application></c> or
/// <c><instrumentation></c>.
/// </summary>
public bool CannotRegisterInStaticConstructor { get; set; }
/// <summary>
/// Marshal methods: methods with [Register(name, sig, connector)], [Export], or
/// constructor registrations ([Register(".ctor", sig, "")] / [JniConstructorSignature]).
/// Constructors are identified by <see cref="MarshalMethodInfo.IsConstructor"/>.
/// Ordered — the index in this list is the method's ordinal for RegisterNatives.
/// </summary>
public IReadOnlyList<MarshalMethodInfo> MarshalMethods { get; init; } = Array.Empty<MarshalMethodInfo> ();
/// <summary>
/// Java constructors to emit in the JCW .java file.
/// Each has a JNI signature and an ordinal index for the nctor_N native method.
/// </summary>
public IReadOnlyList<JavaConstructorInfo> JavaConstructors { get; init; } = [];
/// <summary>
/// Java fields from [ExportField] attributes.
/// Each field is initialized by calling the annotated method.
/// </summary>
public IReadOnlyList<JavaFieldInfo> JavaFields { get; init; } = [];
/// <summary>
/// Information about the activation constructor for this type.
/// May reference a base type's constructor if the type doesn't define its own.
/// </summary>
public ActivationCtorInfo? ActivationCtor { get; init; }
/// <summary>
/// For interfaces and abstract types, the name of the invoker type
/// used to instantiate instances from Java.
/// </summary>
public string? InvokerTypeName { get; init; }
/// <summary>
/// True if this is an open generic type definition.
/// Generic types get TypeMap entries but CreateInstance throws NotSupportedException.
/// </summary>
public bool IsGenericDefinition { get; init; }
/// <summary>
/// Android component attribute data ([Activity], [Service], [BroadcastReceiver], [ContentProvider],
/// [Application], [Instrumentation]) if present on this type. Used for manifest generation.
/// </summary>
public ComponentInfo? ComponentAttribute { get; init; }
}
/// <summary>
/// Describes a marshal method (a method with [Register] or [Export]) on a Java peer type.
/// Contains all data needed to generate a UCO wrapper, a JCW native declaration,
/// and a RegisterNatives call.
/// </summary>
public sealed record MarshalMethodInfo
{
/// <summary>
/// JNI method name, e.g., "onCreate".
/// This is the Java method name (without n_ prefix).
/// </summary>
public required string JniName { get; init; }
/// <summary>
/// JNI method signature, e.g., "(Landroid/os/Bundle;)V".
/// Contains both parameter types and return type.
/// </summary>
public required string JniSignature { get; init; }
/// <summary>
/// The connector string from [Register], e.g., "GetOnCreate_Landroid_os_Bundle_Handler".
/// Null for [Export] methods.
/// </summary>
public string? Connector { get; init; }
/// <summary>
/// Name of the managed method this maps to, e.g., "OnCreate".
/// </summary>
public required string ManagedMethodName { get; init; }
/// <summary>
/// Full name of the type that declares the managed method (may be a base type).
/// Empty when the declaring type is the same as the peer type.
/// </summary>
public string DeclaringTypeName { get; init; } = "";
/// <summary>
/// Assembly name of the type that declares the managed method.
/// Needed for cross-assembly UCO wrapper generation.
/// Empty when the declaring type is the same as the peer type.
/// </summary>
public string DeclaringAssemblyName { get; init; } = "";
/// <summary>
/// The native callback method name, e.g., "n_onCreate".
/// This is the actual method the UCO wrapper delegates to.
/// </summary>
public required string NativeCallbackName { get; init; }
/// <summary>
/// True if this is a constructor registration.
/// </summary>
public bool IsConstructor { get; init; }
/// <summary>
/// True if this method comes from an [Export] attribute (rather than [Register]).
/// [Export] methods use the C# method's access modifier in the JCW Java file
/// instead of always being "public".
/// </summary>
public bool IsExport { get; init; }
/// <summary>
/// Java access modifier for [Export] methods ("public", "protected", "private").
/// Null for [Register] methods (always "public").
/// </summary>
public string? JavaAccess { get; init; }
/// <summary>
/// For [Export] methods: Java exception types that the method declares it can throw.
/// Null for [Register] methods.
/// </summary>
public IReadOnlyList<string>? ThrownNames { get; init; }
/// <summary>
/// For [Export] methods: super constructor arguments string.
/// Null for [Register] methods.
/// </summary>
public string? SuperArgumentsString { get; init; }
/// <summary>
/// True if this method was collected from an implemented interface
/// (Pass 4: CollectInterfaceMethodImplementations), not from the type itself.
/// </summary>
public bool IsInterfaceImplementation { get; init; }
}
/// <summary>
/// Describes a JNI parameter for UCO method generation.
/// </summary>
public sealed record JniParameterInfo
{
/// <summary>
/// JNI type descriptor, e.g., "Landroid/os/Bundle;", "I", "Z".
/// </summary>
public required string JniType { get; init; }
/// <summary>
/// Managed parameter type name, e.g., "Android.OS.Bundle", "System.Int32".
/// </summary>
public string ManagedType { get; init; } = "";
}
/// <summary>
/// Describes a Java constructor to emit in the JCW .java source file.
/// </summary>
public sealed record JavaConstructorInfo
{
/// <summary>
/// JNI constructor signature, e.g., "(Landroid/content/Context;)V".
/// </summary>
public required string JniSignature { get; init; }
/// <summary>
/// Ordinal index for the native constructor method (nctor_0, nctor_1, ...).
/// </summary>
public required int ConstructorIndex { get; init; }
/// <summary>
/// For [Export] constructors: super constructor arguments string.
/// Null for [Register] constructors.
/// </summary>
public string? SuperArgumentsString { get; init; }
}
/// <summary>
/// Describes a Java field from an [ExportField] attribute.
/// The field is initialized by calling the annotated method.
/// </summary>
public sealed record JavaFieldInfo
{
/// <summary>
/// Java field name, e.g., "STATIC_INSTANCE".
/// </summary>
public required string FieldName { get; init; }
/// <summary>
/// Java type name for the field, e.g., "java.lang.String".
/// </summary>
public required string JavaTypeName { get; init; }
/// <summary>
/// Name of the method that initializes this field, e.g., "GetInstance".
/// </summary>
public required string InitializerMethodName { get; init; }
/// <summary>
/// Java access modifier ("public", "protected", "private").
/// </summary>
public required string Visibility { get; init; }
/// <summary>
/// Whether the field is static.
/// </summary>
public bool IsStatic { get; init; }
}
/// <summary>
/// Describes how to call the activation constructor for a Java peer type.
/// </summary>
public sealed record ActivationCtorInfo
{
/// <summary>
/// The type that declares the activation constructor.
/// May be the type itself or a base type.
/// </summary>
public required string DeclaringTypeName { get; init; }
/// <summary>
/// The assembly containing the declaring type.
/// </summary>
public required string DeclaringAssemblyName { get; init; }
/// <summary>
/// The style of activation constructor found.
/// </summary>
public required ActivationCtorStyle Style { get; init; }
}
public enum ActivationCtorStyle
{
/// <summary>
/// Xamarin.Android style: (IntPtr handle, JniHandleOwnership transfer)
/// </summary>
XamarinAndroid,
/// <summary>
/// Java.Interop style: (ref JniObjectReference reference, JniObjectReferenceOptions options)
/// </summary>
JavaInterop,
}