Skip to content

Commit b6895af

Browse files
[TrimmableTypeMap][Core C] Adapt scanner to refactored AssemblyIndex
- Remove Phase 1b (JniNameProviderAttribute merging/reclassification) - Use record 'with' expression for immutable ForceUnconditionalIfPresent - Use .IsNullOrEmpty() extension method - Use record init syntax for RegisterInfo and ExportInfo construction Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 6445238 commit b6895af

File tree

1 file changed

+6
-17
lines changed

1 file changed

+6
-17
lines changed

src/Microsoft.Android.Sdk.TrimmableTypeMap/Scanner/JavaPeerScanner.cs

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ public List<JavaPeerInfo> Scan (IReadOnlyList<string> assemblyPaths)
8585
assemblyCache [index.AssemblyName] = index;
8686
}
8787

88-
// Phase 1b: Merge IJniNameProviderAttribute implementor sets from all assemblies
89-
// and re-classify any attributes that weren't recognized in the initial pass
90-
// (e.g., user assembly references ActivityAttribute from Mono.Android.dll).
91-
var mergedJniNameProviders = new HashSet<string> (StringComparer.Ordinal);
92-
foreach (var index in assemblyCache.Values) {
93-
mergedJniNameProviders.UnionWith (index.JniNameProviderAttributes);
94-
}
95-
foreach (var index in assemblyCache.Values) {
96-
index.ReclassifyAttributes (mergedJniNameProviders);
97-
}
98-
9988
// Phase 2: Analyze types using cached indices
10089
var resultsByManagedName = new Dictionary<string, JavaPeerInfo> (StringComparer.Ordinal);
10190

@@ -140,7 +129,7 @@ static void ForceUnconditionalIfPresent (Dictionary<string, JavaPeerInfo> result
140129
}
141130

142131
if (resultsByManagedName.TryGetValue (managedTypeName, out var peer)) {
143-
peer.IsUnconditional = true;
132+
resultsByManagedName [managedTypeName] = peer with { IsUnconditional = true };
144133
}
145134
}
146135

@@ -167,7 +156,7 @@ void ScanAssembly (AssemblyIndex index, Dictionary<string, JavaPeerInfo> results
167156
index.RegisterInfoByType.TryGetValue (typeHandle, out var registerInfo);
168157
index.AttributesByType.TryGetValue (typeHandle, out var attrInfo);
169158

170-
if (registerInfo is not null && !string.IsNullOrEmpty (registerInfo.JniName)) {
159+
if (registerInfo is not null && !registerInfo.JniName.IsNullOrEmpty ()) {
171160
jniName = registerInfo.JniName;
172161
compatJniName = jniName;
173162
doNotGenerateAcw = registerInfo.DoNotGenerateAcw;
@@ -385,7 +374,7 @@ static bool TryGetMethodRegisterInfo (MethodDefinition methodDef, AssemblyIndex
385374
}
386375
}
387376

388-
if (string.IsNullOrEmpty (exportName)) {
377+
if (exportName.IsNullOrEmpty ()) {
389378
exportName = index.Reader.GetString (methodDef.Name);
390379
}
391380

@@ -394,8 +383,8 @@ static bool TryGetMethodRegisterInfo (MethodDefinition methodDef, AssemblyIndex
394383
var jniSig = BuildJniSignatureFromManaged (sig);
395384

396385
return (
397-
new RegisterInfo (exportName, jniSig, null, false),
398-
new ExportInfo (thrownNames, superArguments)
386+
new RegisterInfo { JniName = exportName, Signature = jniSig, Connector = null, DoNotGenerateAcw = false },
387+
new ExportInfo { ThrownNames = thrownNames, SuperArgumentsString = superArguments }
399388
);
400389
}
401390

@@ -692,7 +681,7 @@ bool ExtendsJavaPeer (TypeDefinition typeDef, AssemblyIndex index)
692681
current = index.Reader.GetTypeDefinition (parentHandle);
693682

694683
// Check if the parent has a registered JNI name
695-
if (index.RegisterInfoByType.TryGetValue (parentHandle, out var parentRegister) && !string.IsNullOrEmpty (parentRegister.JniName)) {
684+
if (index.RegisterInfoByType.TryGetValue (parentHandle, out var parentRegister) && !parentRegister.JniName.IsNullOrEmpty ()) {
696685
parentJniName = parentRegister.JniName;
697686
break;
698687
}

0 commit comments

Comments
 (0)