Skip to content

Commit c34eed5

Browse files
committed
[Xamarin.Android.Tools.Bytecode] Fix for finding public setters with old kotlinc versions.
1 parent 1adb796 commit c34eed5

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,10 +389,12 @@ static void FixupField (FieldInfo? field, KotlinProperty metadata)
389389
return null;
390390

391391
// Public/protected getters look like "getFoo"
392+
// Public/protected getters with unsigned types look like "getFoo-abcdefg"
392393
// Internal getters look like "getFoo$main"
394+
// Internal getters with unsigned types look like "getFoo-WZ4Q5Ns$main"
393395
var possible_methods = property.IsInternalVisibility ?
394-
klass.Methods.Where (method => method.Name.StartsWith ($"get{property.Name.Capitalize ()}$", StringComparison.Ordinal)) :
395-
klass.Methods.Where (method => method.Name.Equals ($"get{property.Name.Capitalize ()}", StringComparison.Ordinal));
396+
klass.Methods.Where (method => method.GetMethodNameWithoutSuffix ().StartsWith ($"get{property.Name.Capitalize ()}$", StringComparison.Ordinal)) :
397+
klass.Methods.Where (method => method.GetMethodNameWithoutSuffix ().Equals ($"get{property.Name.Capitalize ()}", StringComparison.Ordinal));
396398

397399
possible_methods = possible_methods.Where (method =>
398400
method.GetParameters ().Length == 0 &&
@@ -409,10 +411,12 @@ static void FixupField (FieldInfo? field, KotlinProperty metadata)
409411
return null;
410412

411413
// Public/protected setters look like "setFoo"
414+
// Public/protected setters with unsigned types look like "setFoo-abcdefg"
412415
// Internal setters look like "setFoo$main"
416+
// Internal setters with unsigned types look like "setFoo-WZ4Q5Ns$main"
413417
var possible_methods = property.IsInternalVisibility ?
414-
klass.Methods.Where (method => method.Name.StartsWith ($"set{property.Name.Capitalize ()}$", StringComparison.Ordinal)) :
415-
klass.Methods.Where (method => method.Name.Equals ($"set{property.Name.Capitalize ()}", StringComparison.Ordinal));
418+
klass.Methods.Where (method => method.GetMethodNameWithoutSuffix ().StartsWith ($"set{property.Name.Capitalize ()}$", StringComparison.Ordinal)) :
419+
klass.Methods.Where (method => method.GetMethodNameWithoutSuffix ().Equals ($"set{property.Name.Capitalize ()}", StringComparison.Ordinal));
416420

417421
possible_methods = possible_methods.Where (method =>
418422
property.ReturnType != null &&

src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinUtilities.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public static string GetMethodNameWithoutSuffix (this MethodInfo method)
8383
// - add-impl
8484
// - add-H3FcsT8
8585
// We strip them for trying to match up the metadata to the MethodInfo
86-
var index = method.Name.IndexOfAny (new [] { '-', '$' });
86+
var index = method.Name.IndexOfAny (new [] { '-' });
8787

8888
return index >= 0 ? method.Name.Substring (0, index) : method.Name;
8989
}

0 commit comments

Comments
 (0)