[Xamarin.Android.Tools.Bytecode] Support @JvmOverloads #651
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
@moljac ran into an interesting warning from
class-parsewhenbinding OfficeUIFrabric:
For starters, this shouldn't be a warning; it's not actionable.
There is nothing a user can do to fix this warning; it's only
meaningful to the Java.Interop team.
Update
Xamarin.Android.Tools.Bytecode.MethodInfo.GetParameters()sothat these messages are debug messages, not warnings.
class-parseknows how many parameters are present based on the JNImethod descriptor, in this case
(Landroid/content/Context;)V, whichspecifies one parameter type. The JNI descriptor doesn't contain
parameter name information; where do parameter names come from?
If the
.classfile was built viajavac -parameters, then theMethodParametersAttributeblob can be used; see 4273e5c.However, before checking for
MethodParametersAttribute,class-parsewill attempt to use theLocalVariableTableAttributeand
LocalVariableTableEntryvalues to infer parameter names.As part of this inference, method parameters are assumed to be
variables with
LocalVariableTableEntry.StartPCis 0; fromclass-parse --dump BottomNavigationView.class:Next,
class-parsewill "skip" the first variable for instancemethods. This results in "skipping" the
contextvariable, resultingin the message:
To fix this,
class-parseneeds a stricter "skip thethisparameter" check: the first parameter should only be skipped when:
staticmethod, anddescriptor of the declaring type.
Additionally, update the code style to use
enumValue.HasFlag(V)instead of
(enumValue & V) == Vfor readability.Finally, why was this failing in the first place? In some
circumstances, when the Kotlin [
@JvmOverloads][2] annotation is usedon a
constructor, Kotlin will emit all possible overloads for theconstructor, and in many of those overloads the
thisparameterwon't be present in the
LocalVariableTableAttributedata, as seenabove with
BottomNavigationView.