-
Notifications
You must be signed in to change notification settings - Fork 64
[generator] Fix localization error. #702
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
Conversation
| string ContextMethodString => ContextMethod != null ? "in method " + ContextMethod.Name + " " : null; | ||
| string ContextTypeString => ContextType != null ? "in managed type " + ContextType.FullName : null; | ||
| public string ContextString => ContextFieldString + ContextMethodString + ContextTypeString; | ||
| public string ContextTypeMember => (ContextType != null ? $"{ContextType.FullName}." : string.Empty) + ContextMethod?.Name ?? ContextField?.Name; |
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.
When ContextMethod isn't null, could this also include the parameter list?
The example in the PR message, ColorStateList.CreateFromXml(), contains two overloads. It would presumably be helpful/useful if the warning message mentioned which overload was at fault:
warning BG8800: Unknown return type 'System.Xml.XmlReader' for member 'Android.Content.Res.ColorStateList.CreateFromXml(Android.Content.Res.Resources, System.Xml.XmlReader)'.
| string ContextMethodString => ContextMethod != null ? "in method " + ContextMethod.Name + " " : null; | ||
| string ContextTypeString => ContextType != null ? "in managed type " + ContextType.FullName : null; | ||
| public string ContextString => ContextFieldString + ContextMethodString + ContextTypeString; | ||
| public string ContextTypeMember => (ContextType != null ? $"{ContextType.FullName}." : string.Empty) + ContextMethod?.Name ?? ContextField?.Name; |
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.
Considering that this method performs a string allocation, should it perhaps instead be a GetContextTypeMember() method?
|
Squash-and-merge message: In d664e90e we made `generator` localizable. One of the changes was
this pattern:
- Report.Warning (0, Report.WarningReturnValue + 0, "Unknown return type {0} {1}.", java_type, context.ContextString);
+ Report.LogCodedWarning (0, Report.WarningUnknownReturnType, java_type, context.ContextString);
in which `Report.WarningUnknownReturnType` is:
"Unknown return type '{0}' for member '{1}'."
However `context.ContextString` generates a hard to localize string, e.g.
in method CreateFromXml in managed type Android.Content.Res.ColorStateList
resulting in messages such as:
warning BG8800: Unknown return type 'System.Xml.XmlReader' for member 'in method CreateFromXml in managed type Android.Content.Res.ColorStateList'.
This message doesn't "look right", nor is it itself localizable.
Instead, add a `context.GetContextTypeMember ()` method which formats the
member as a type signature, which doesn't need to be separately
localized and "reads correctly" in context:
warning BG8800: Unknown return type 'System.Xml.XmlReader' for member 'Android.Content.Res.ColorStateList.CreateFromXml(Android.Content.Res.Resources, System.Xml.XmlReader)'.Note that ^^ requires that |
| var output = ContextType?.FullName ?? string.Empty; | ||
|
|
||
| if (ContextMethod != null) { | ||
| output += $"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.RawType).ToArray ())})"; |
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.
The p.RawType here confuses me.
For starers, I can't find it?
% git grep 'RawType'
tests/Xamarin.Android.Tools.ApiXmlAdjuster-Tests/api-24.xml.in: name="getRawType"(Yet the PR builds, which makes this even more confusing to me.)
Secondly, do we want the "signature" to contain Java names or C# names? I'd think we'd want the Parameter.Type property?
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.
This point of the process is looking up Java types (type) and converting them to C# types (sym). So sym is still null, causing an NRE if we use Parameter.Type.
In #689 we made
generatorlocalizable. One of the changes was this pattern:However
context.ContextStringgenerates a hard to localize string like:resulting in warnings like this:
Instead, create a
context.ContextTypeMembermethod that formats the member as just a type signature, which fits the localized message: