Skip to content

Conversation

@brendanzagaeski
Copy link
Contributor

@brendanzagaeski brendanzagaeski commented Oct 26, 2018

Context: #1560

Background discussion about the new wording for this particular warning
and error:

The new wording aims to be more actionable. It is also more compact
than the old wording when there are multiple conflicts.

A possible future enhancement could be to move the warning into the
ConvertCustomView task so that it only appears when a managed type
name from an Android resource file matches more than one line in the
acw-map. That way, if a user wants to solve the issue by using
[Register] attributes or assembly-qualified type names rather than
renaming the managed types, the build process will automatically stop
showing the warning.

This pull request also includes a fix from Jonathan Peppers for
GenerateJavaStubs. That fix is not strictly required for the changes
to the warning and error, but it is included here because it touches
neighboring source code.
Fixes: #2266

@brendanzagaeski brendanzagaeski added the do-not-merge PR should not be merged. label Oct 26, 2018
brendanzagaeski added a commit to brendanzagaeski/java.interop that referenced this pull request Oct 26, 2018
Context: dotnet/android#2349

This commit introduces a new extension method `GetAssemblyName()` that
provides the assembly name portion of
`GetPartialAssemblyQualifiedName()` so that `GenerateJavaStubs` doesn't
have to do any string splitting to get the assembly name for warning
XA4214.
@brendanzagaeski
Copy link
Contributor Author

As currently written, this pull request will require dotnet/java-interop#390 to be merged and bumped into xamarin-android before it will build successfully. I'd also be happy to adjust this PR so that it instead splits the output from GetPartialAssemblyQualifiedName() to get the assembly name, if that seems better. In that case, the Java.Interop PR can be closed without merging it.

@jonpryor
Copy link
Contributor

The macOS PR Build failed to build:

18:23:48   Tasks/GenerateJavaStubs.cs(164,67): error CS1061: 'TypeDefinition' does not contain a definition for 'GetAssemblyName' and no extension method 'GetAssemblyName' accepting a first argument of type 'TypeDefinition' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj]
18:23:48   Tasks/GenerateJavaStubs.cs(165,46): error CS1061: 'TypeDefinition' does not contain a definition for 'GetAssemblyName' and no extension method 'GetAssemblyName' accepting a first argument of type 'TypeDefinition' could be found (are you missing a using directive or an assembly reference?) [/Users/builder/jenkins/workspace/xamarin-android-pr-builder/xamarin-android/src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj]

@brendanzagaeski
Copy link
Contributor Author

The macOS PR Build failed to build:

Ah yes, whoops. I meant (and forgot) to look up whether there was a @monojenkins message that would skip building this PR until it was settled whether to use dotnet/java-interop#390 or split the assembly name out from GetPartialAssemblyQualifiedName(). I have now added @monojenkins skip to the PR description, so I think this PR won't try to build automatically any more.

@brendanzagaeski
Copy link
Contributor Author

Ah nope, it looks like it's still trying to build the PR automatically. Maybe I would have had to include @monojenkins skip in the original version of the description?

brendanzagaeski added a commit to brendanzagaeski/java.interop that referenced this pull request Nov 7, 2018
Context: dotnet/android#2349

This commit introduces a new extension method `GetPartialAssemblyName()`
that provides just the assembly name portion of
`GetPartialAssemblyQualifiedName()` so that `GenerateJavaStubs` doesn't
need to do any string splitting to get the assembly name for warning
XA4214.  It also makes a small replacement in `JavaNativeTypeManager` to
take advantage of the new extension method for readability.

This new extension method returns a partial assembly name that is
specifically just the *first* part of a fully qualified assembly name.
The documentation for [System.Reflection.AssemblyName][0] and
[`Type.GetType()`][1] refers to this first part as the *simple name* of
the assembly.

Another detail about terminology that might be useful to mention is that
a type name with no qualifiers is called the *simple name* of the type,
while a type name qualified with either a partial or full assembly name
is called *fully qualified*.  So for example, the
`GetPartialAssemblyQualifiedName()` extension method returns a fully
qualified type name, even though it is only qualified with a partial
assembly name.

[0]: https://docs.microsoft.com/dotnet/api/system.reflection.assemblyname?view=netframework-4.7.2#remarks
[1]: https://docs.microsoft.com/dotnet/api/system.type.gettype?view=netframework-4.7.2#remarks
jonpryor pushed a commit to dotnet/java-interop that referenced this pull request Nov 8, 2018
…#390)

Context: dotnet/android#2349

This commit introduces a new `GetPartialAssemblyName()` extension
method on `TypeReference` which provides just the assembly name
portion of `GetPartialAssemblyQualifiedName()` so that
`GenerateJavaStubs` doesn't need to do any string splitting to get
the assembly name for warning XA4214.  It also makes a small
replacement in `JavaNativeTypeManager` to take advantage of the new
extension method for readability.

This new extension method returns a partial assembly name that is
specifically just the *first* part of a fully qualified assembly name.
The documentation for [`System.Reflection.AssemblyName`][0] and
[`Type.GetType()`][1] refers to this first part as the *simple name*
of the assembly.

Another detail about terminology that might be useful to mention is
that a type name with no qualifiers is called the *simple name* of
the type, while a type name qualified with either a partial or full
assembly name is called *fully qualified*.  For example, the
`GetPartialAssemblyQualifiedName()` extension method returns a fully
qualified type name, even though it is only qualified with a partial
assembly name.

[0]: https://docs.microsoft.com/dotnet/api/system.reflection.assemblyname?view=netframework-4.7.2#remarks
[1]: https://docs.microsoft.com/dotnet/api/system.type.gettype?view=netframework-4.7.2#remarks
@brendanzagaeski brendanzagaeski removed the do-not-merge PR should not be merged. label Nov 9, 2018
Log.LogCodedWarning (
"XA4214",
"The managed type `{0}` exists in more than one assembly: {1}. " +
"Please refactor the managed type names in these assemblies so that they are not identical.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current message mentions what will be used:

References to the type `Foo.Bar` will refer to `Foo.Bar, Baz`.

This information is lost by this PR. It should be preserved.

This might be a scenario where we want multiple warnings for the "same" issue:

warning XA4214: The managed type `Foo.Bar` exists in more than one assembly: Baz, Qux, Quux.
warning XA4214: References to the type `Foo.Bar` will refer to `Foo.Bar, Baz`.

foreach (var kvp in managedConflicts) {
Log.LogCodedWarning (
"XA4214",
"The managed type `{0}` exists in more than one assembly: {1}. " +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grammar: there's more than one assembly, so we should pluralize accordingly:

warning XA4214: The managed type `Foo.Bar` is defined in the assemblies: Baz, Qux, Quux.

jonathanpeppers and others added 2 commits January 7, 2019 20:04
…vaStubs

Context: dotnet#1560

Background discussion about the new wording for this particular warning
and error:

  * dotnet#2258 (comment)
  * dotnet#2258 (comment)

The new wording aims to be more actionable.  It is also more compact
than the old wording when there are multiple conflicts.

The `Dictionary` initializations follow the style used in [c362fe5][0].
Since these 2 new dictionaries should usually be empty, they are set to
an initial capacity of 0.  The current implementation of `Dictionary`
defaults to an initial capacity of 0, but the [documentation][1] doesn't
mention 0 specifically, so it seems reasonable to specify it.  Another
idea would be to initialize each dictionary only when a corresponding
conflict is found, but that might make the code trickier to read.

A possible future enhancement could be to move the warning into the
`ConvertCustomView` task so that it only appears when a managed type
name from an Android resource file matches more than one line in the
acw-map.  That way, if a user wants to solve the issue by using
`[Register]` attributes or assembly-qualified type names rather than
renaming the managed types, the build process will automatically stop
showing the warning.

[0]: dotnet@c362fe5
[1]: https://docs.microsoft.com/dotnet/api/system.collections.generic.dictionary-2.-ctor
@brendanzagaeski
Copy link
Contributor Author

Changes in the latest edit:

Rebase on master. Along the way, adjust the style of the Dictionary initializations to follow the style from c362fe5. Since these dictionaries should usually be empty, set the initial capacity to 0. The current implementation of Dictionary defaults to an initial capacity of 0, but the documentation doesn't mention 0 specifically, so it seems reasonable to specify it. Another idea would be to initialize each dictionary only when a corresponding conflict is found, but I think that might make the code trickier to read.

Address the requested wording changes. I'm proposing "multiple assemblies" instead of "the assemblies" to give users a small additional indication that the warning wouldn't happen if the type name only existed in one assembly. I'm happy to change it back to "the" if this seems silly.

Make the included tests a little stricter by having them check for inclusion of the type name and assembly names in the warning and error messages.

@jonpryor
Copy link
Contributor

jonpryor commented Jan 9, 2019

build

@jonpryor jonpryor merged commit efbec22 into dotnet:master Jan 15, 2019
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Duplicate Java Callable Wrapper names are allowed when they shouldn't be.

4 participants