Skip to content

Commit

Permalink
[Xamarin.Android.Tools.Bytecode] Fix for finding public setters with …
Browse files Browse the repository at this point in the history
…old `kotlinc` versions.
  • Loading branch information
jpobst committed Oct 30, 2023
1 parent 1adb796 commit c34eed5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
12 changes: 8 additions & 4 deletions src/Xamarin.Android.Tools.Bytecode/Kotlin/KotlinFixups.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,10 +389,12 @@ static void FixupField (FieldInfo? field, KotlinProperty metadata)
return null;

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

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

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

possible_methods = possible_methods.Where (method =>
property.ReturnType != null &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public static string GetMethodNameWithoutSuffix (this MethodInfo method)
// - add-impl
// - add-H3FcsT8
// We strip them for trying to match up the metadata to the MethodInfo
var index = method.Name.IndexOfAny (new [] { '-', '$' });
var index = method.Name.IndexOfAny (new [] { '-' });

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

0 comments on commit c34eed5

Please sign in to comment.