-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[generator] Mark generated .cs files as generated (#1052)
Fixes: #1051 Context: dotnet/android#7449 [Roslyn determines if a file is generated or not][0] by looking for the strings `<autogenerated` or `<auto-generated` within the file. Roslyn analyzers specify whether they want to scan generated code or not using [`GeneratedCodeAnalysisFlags`][1]. Many analyzers *disable* their checks when processing generated code. Until now, `generator` output did *not* indicate that the output is generated code. Consequently, many Roslyn analyzers would process and issue warnings about generated code, warnings which would *not* be emitted if the analyzer knew it was generated code: …\src\Uno.UI.BindingHelper.Android\obj\Release\net6.0-android\generated\src\Java.Interop.__TypeRegistrations.cs(16,6): error CA1825: Avoid unnecessary zero-length array allocations. Use Array.Empty<string>() instead. …\src\Uno.UI.BindingHelper.Android\obj\Release\net6.0-android\generated\src\Java.Interop.__TypeRegistrations.cs(18,6): error CA1825: Avoid unnecessary zero-length array allocations. Use Array.Empty<Converter<string, Type>>() instead. …\src\Uno.UI.BindingHelper.Android\obj\Release\net6.0-android\generated\src\Uno.UI.UnoRecyclerView.cs(168,25): error CA1812: 'UnoRecyclerViewInvoker' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). …\src\Uno.UI.BindingHelper.Android\obj\Release\net6.0-android\generated\src\Uno.UI.UnoViewGroup.cs(829,25): error CA1812: 'UnoViewGroupInvoker' is an internal class that is apparently never instantiated. If so, remove the code from the assembly. If this class is intended to contain only static members, make it 'static' (Module in Visual Basic). Update `generator` so that generated `.cs` files contain the comment: //------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ This will help ensure that Roslyn considers the files to contain generated code, which will prevent some analyzers from checking those files, which will reduce the number of warnings or errors emitted. This should allow slightly faster builds with fewer warnings. Additionally, it should help make it clearer to users that these files should not be modified by hand (dotnet/android#7449). Note: by default [Roslyn disables Nullable Reference Types (NRT)][2] for code marked as "generated", causing: Error CS8669: The annotation for nullable reference types should only be used in code within a '#nullable' annotations context. Auto-generated code requires an explicit '#nullable' directive in source. We have to explicitly restore NRT back to the project settings for our generated files with: #nullable restore [0]: https://github.com/dotnet/roslyn/blob/3f694a3c39c44b5dccb4aaaa163080bdb3ad412f/src/Compilers/Core/Portable/InternalUtilities/GeneratedCodeUtilities.cs [1]: https://learn.microsoft.com/en-us/dotnet/api/microsoft.codeanalysis.diagnostics.analysiscontext.configuregeneratedcodeanalysis [2]: https://github.com/dotnet/roslyn/blob/70e158ba6c2c99bd3c3fc0754af0dbf82a6d353d/docs/features/nullable-reference-types.md#generated-code
- Loading branch information
Showing
200 changed files
with
2,006 additions
and
0 deletions.
There are no files selected for viewing
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.BasePublicClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.ExtendPublicClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.PublicFinalClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/AccessModifiers/Xamarin.Test.TestClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Android.Graphics.Color/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Android.Graphics.Color/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Arrays/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Arrays/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/CSharpKeywords/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/CSharpKeywords/Java.Lang.Throwable.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/CSharpKeywords/Xamarin.Test.CSharpKeywords.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Constructors/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Constructors/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Constructors/Xamarin.Test.SomeObject2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Core_ClassParse/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Core_ClassParse/Java.Lang.String.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Core_ClassParse/Xamarin.Google.Composable.MyClass.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/Core_ClassParse/Xamarin.Test.Invalidnames.In.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
...nerator-Tests/expected.ji/Core_ClassParse/Xamarin.Test.Invalidnames.InvalidNameMembers.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/InterfaceMethodsConflict/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/InterfaceMethodsConflict/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/InterfaceMethodsConflict/Xamarin.Test.SomeObject2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/NonStaticFields/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/NonStaticFields/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/NormalProperties/Java.Lang.Object.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
tests/generator-Tests/expected.ji/NormalProperties/Xamarin.Test.SomeObject.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.