-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Xamarin.Android.Tools.Bytecode] Only hide getters/setters for internal properties. #1151
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics.CodeAnalysis; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
@@ -8,6 +9,18 @@ namespace Xamarin.Android.Tools.Bytecode | |
{ | ||
public static class KotlinUtilities | ||
{ | ||
[return: NotNullIfNotNull (nameof (value))] | ||
public static string? Capitalize (this string? value) | ||
{ | ||
if (string.IsNullOrWhiteSpace (value)) | ||
return value; | ||
|
||
if (value.Length < 1) | ||
return value; | ||
|
||
return char.ToUpperInvariant (value [0]) + value.Substring (1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This feels fragile and prone to bite us, e.g. I half wonder if looking for case- insensitive checks elsewhere would be "better", as with this approach we're "guessing" at the intended capitalization, at the cost of not allowing "case-differing properties". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed that this feels fragile, but it does seem to be what Kotlin does: // Kotlin
internal val Capital1 = 0
internal val capital2 = 0
internal val cAPitAL3 = 0
// Generated Java
private final int Capital1;
private final int capital2;
private final int cAPitAL3;
public final int getCapital1$main() {
return this.Capital1;
}
public final int getCapital2$main() {
return this.capital2;
}
public final int getCAPitAL3$main() {
return this.cAPitAL3;
} "case-differing properties" do seem to be allowed: // Kotlin
internal val Foo = 0
internal val FOO = 0
// Generated Java
private final int Foo;
private final int FOO;
public final int getFoo$main() {
return this.Foo;
}
public final int getFOO$main() {
return this.FOO;
} The "good" news is that it does guard against case-differing property names that would create a clash: // Kotlin
internal val foo = 0
internal val Foo = 0
error G6DDBDC0F: platform declaration clash: The following declarations have the same JVM signature (getFoo$main()I):
fun `<get-Foo>`(): Int defined in NameShadowing
fun `<get-foo>`(): Int defined in NameShadowing
internal val foo = 0 |
||
} | ||
|
||
public static string ConvertKotlinTypeSignature (KotlinType? type, KotlinFile? metadata = null, bool convertUnsignedToPrimitive = true) | ||
{ | ||
if (type is null) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to verify/validate this is redonkulous:
Fortunately, instead of trying to make sense of their code, I can just have the Java compiler tell me:
16384 is 0x4000 which is 0b_0100_0000_0000_0000, which is 0b_001000000_00_00_000_0. Things match!