Skip to content

Commit e9d90f7

Browse files
committed
[generator] less aggressive obfuscation marking.
This is a fixup for c51469e, as well as bugfix for: https://bugzilla.xamarin.com/show_bug.cgi?id=51337 What's happening behind bug #51337 was this: BINDINGSGENERATOR: warning BG8800: Unknown parameter type org.osmdroid.ResourceProxy.bitmap in method GetBitmap in managed type OsmDroid.DefaultResourceProxyImpl. This was, because, "bitmap" is all lowercased and was marked as obfuscated (because, WHY NAME A CLASS ALL IN LOWERCASE!?). Such classes should not exist, or should be marked as "obfuscated='false'". However what bug #51337 implies is that people are not going to make this additional markup for generator improvements. What this generator change does is then - a hack. A hack to mark "classes with very short names" as obfuscated, instead of "all lowercase or number". As commented on c51469e, there isn't good way to check API element siblings (it can check sibling names every time at all expensive calculation). So we just count the sibling nodes and if name length is short enough to fit within the number of classes, we mark as obfucated.
1 parent 39f1744 commit e9d90f7

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

tools/generator/GenBaseSupport.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public XmlGenBaseSupport (XmlElement pkg, XmlElement elem)
204204
full_name = String.Format ("{0}.{1}{2}", ns, idx > 0 ? StringRocks.TypeToPascalCase (java_name.Substring (0, idx + 1)) : String.Empty, name);
205205
}
206206

207-
obfuscated = IsObfuscatedName (java_name) && elem.XGetAttribute ("obfuscated") != "false";
207+
obfuscated = IsObfuscatedName (pkg.ChildNodes.Count, java_name) && elem.XGetAttribute ("obfuscated") != "false";
208208
}
209209

210210
public override bool IsAcw {
@@ -302,12 +302,14 @@ public override bool ValidateNamespace ()
302302
return true;
303303
}
304304

305-
bool IsObfuscatedName (String name)
305+
bool IsObfuscatedName (int threshold, string name)
306306
{
307307
if (name.StartsWith ("R.", StringComparison.Ordinal))
308308
return false;
309309
int idx = name.LastIndexOf ('.');
310310
string last = idx < 0 ? name : name.Substring (idx + 1);
311+
if (threshold <= Math.Pow (26, last.Length - 1))
312+
return false;
311313
if (last.Any (c => (c < 'a' || 'z' < c) && (c < '0' || '9' < c)))
312314
return false;
313315
return true;

0 commit comments

Comments
 (0)