Skip to content

Commit 79b36fb

Browse files
committed
Switched to global:: paths for other generated files
1 parent 0ed3e4d commit 79b36fb

File tree

3 files changed

+74
-77
lines changed

3 files changed

+74
-77
lines changed

Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/ObservablePropertyGenerator.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public void Execute(GeneratorExecutionContext context)
5656
/// <param name="classDeclaration">The <see cref="ClassDeclarationSyntax"/> node to process.</param>
5757
/// <param name="classDeclarationSymbol">The <see cref="INamedTypeSymbol"/> for <paramref name="classDeclaration"/>.</param>
5858
/// <param name="items">The sequence of fields to process.</param>
59-
private static void OnExecute(
59+
private void OnExecute(
6060
GeneratorExecutionContext context,
6161
ClassDeclarationSyntax classDeclaration,
6262
INamedTypeSymbol classDeclarationSymbol,
@@ -71,7 +71,7 @@ private static void OnExecute(
7171
var classDeclarationSyntax =
7272
ClassDeclaration(classDeclarationSymbol.Name)
7373
.WithModifiers(classDeclaration.Modifiers)
74-
.AddMembers(items.Select(static item => CreatePropertyDeclaration(item.LeadingTrivia, item.FieldSymbol)).ToArray());
74+
.AddMembers(items.Select(item => CreatePropertyDeclaration(item.LeadingTrivia, item.FieldSymbol)).ToArray());
7575

7676
TypeDeclarationSyntax typeDeclarationSyntax = classDeclarationSyntax;
7777

@@ -92,15 +92,12 @@ private static void OnExecute(
9292

9393
// Create the final compilation unit to generate (with leading trivia)
9494
var source =
95-
CompilationUnit().AddUsings(
96-
UsingDirective(IdentifierName("System.Collections.Generic")).WithLeadingTrivia(TriviaList(
97-
Comment("// Licensed to the .NET Foundation under one or more agreements."),
98-
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
99-
Comment("// See the LICENSE file in the project root for more information."),
100-
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))),
101-
UsingDirective(IdentifierName("System.Diagnostics")),
102-
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis"))).AddMembers(
103-
NamespaceDeclaration(IdentifierName(namespaceName))
95+
CompilationUnit().AddMembers(
96+
NamespaceDeclaration(IdentifierName(namespaceName)).WithLeadingTrivia(TriviaList(
97+
Comment("// Licensed to the .NET Foundation under one or more agreements."),
98+
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
99+
Comment("// See the LICENSE file in the project root for more information."),
100+
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true))))
104101
.AddMembers(typeDeclarationSyntax))
105102
.NormalizeWhitespace()
106103
.ToFullString();
@@ -116,7 +113,7 @@ private static void OnExecute(
116113
/// <param name="fieldSymbol">The input <see cref="IFieldSymbol"/> instance to process.</param>
117114
/// <returns>A generated <see cref="PropertyDeclarationSyntax"/> instance for the input field.</returns>
118115
[Pure]
119-
private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaList leadingTrivia, IFieldSymbol fieldSymbol)
116+
private PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaList leadingTrivia, IFieldSymbol fieldSymbol)
120117
{
121118
// Get the field type and the target property name
122119
string
@@ -154,14 +151,15 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
154151
// Construct the generated property as follows:
155152
//
156153
// <FIELD_TRIVIA>
157-
// [DebuggerNonUserCode]
158-
// [ExcludeFromCodeCoverage]
154+
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
155+
// [global::System.Diagnostics.DebuggerNonUserCode]
156+
// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
159157
// public <FIELD_TYPE> <PROPERTY_NAME>
160158
// {
161159
// get => <FIELD_NAME>;
162160
// set
163161
// {
164-
// if (!EqualityComparer<<FIELD_TYPE>>.Default.Equals(<FIELD_NAME>, value))
162+
// if (!global::System.Collections.Generic.EqualityComparer<<FIELD_TYPE>>.Default.Equals(<FIELD_NAME>, value))
165163
// {
166164
// OnPropertyChanging(); // Optional
167165
// <FIELD_NAME> = value;
@@ -172,8 +170,13 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
172170
return
173171
PropertyDeclaration(IdentifierName(typeName), Identifier(propertyName))
174172
.AddAttributeLists(
175-
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
176-
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))))
173+
AttributeList(SingletonSeparatedList(
174+
Attribute(IdentifierName($"global::System.CodeDom.Compiler.GeneratedCode"))
175+
.AddArgumentListArguments(
176+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(GetType().FullName))),
177+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(GetType().Assembly.GetName().Version.ToString())))))),
178+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode")))),
179+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))))
177180
.WithLeadingTrivia(leadingTrivia)
178181
.AddModifiers(Token(SyntaxKind.PublicKeyword))
179182
.AddAccessorListAccessors(
@@ -190,7 +193,7 @@ private static PropertyDeclarationSyntax CreatePropertyDeclaration(SyntaxTriviaL
190193
SyntaxKind.SimpleMemberAccessExpression,
191194
MemberAccessExpression(
192195
SyntaxKind.SimpleMemberAccessExpression,
193-
GenericName(Identifier("EqualityComparer"))
196+
GenericName(Identifier("global::System.Collections.Generic.EqualityComparer"))
194197
.AddTypeArgumentListArguments(IdentifierName(typeName)),
195198
IdentifierName("Default")),
196199
IdentifierName("Equals")))

Microsoft.Toolkit.Mvvm.SourceGenerators/ComponentModel/ObservableValidatorValidateAllPropertiesGenerator.cs

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,18 @@ public void Execute(GeneratorExecutionContext context)
4545
// Prepare the attributes to add to the first class declaration
4646
AttributeListSyntax[] classAttributes = new[]
4747
{
48-
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("DebuggerNonUserCode")))),
49-
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("ExcludeFromCodeCoverage")))),
5048
AttributeList(SingletonSeparatedList(
51-
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
52-
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
49+
Attribute(IdentifierName($"global::System.CodeDom.Compiler.GeneratedCode"))
50+
.AddArgumentListArguments(
51+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(GetType().FullName))),
52+
AttributeArgument(LiteralExpression(SyntaxKind.StringLiteralExpression, Literal(GetType().Assembly.GetName().Version.ToString())))))),
53+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.DebuggerNonUserCode")))),
54+
AttributeList(SingletonSeparatedList(Attribute(IdentifierName("global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage")))),
5355
AttributeList(SingletonSeparatedList(
54-
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
56+
Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments(
57+
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))),
58+
AttributeList(SingletonSeparatedList(
59+
Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments(
5560
AttributeArgument(LiteralExpression(
5661
SyntaxKind.StringLiteralExpression,
5762
Literal("This type is not intended to be used directly by user code"))))))
@@ -68,38 +73,30 @@ public void Execute(GeneratorExecutionContext context)
6873
//
6974
// #pragma warning disable
7075
//
71-
// using System;
72-
// using System.ComponentModel;
73-
// using System.Diagnostics;
74-
// using System.Diagnostics.CodeAnalysis;
75-
//
7676
// namespace Microsoft.Toolkit.Mvvm.ComponentModel.__Internals
7777
// {
78-
// [DebuggerNonUserCode]
79-
// [ExcludeFromCodeCoverage]
80-
// [EditorBrowsable(EditorBrowsableState.Never)]
81-
// [Obsolete("This type is not intended to be used directly by user code")]
78+
// [global::System.CodeDom.Compiler.GeneratedCode("...", "...")]
79+
// [global::System.Diagnostics.DebuggerNonUserCode]
80+
// [global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
81+
// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
82+
// [global::System.Obsolete("This type is not intended to be used directly by user code")]
8283
// internal static partial class __ObservableValidatorExtensions
8384
// {
84-
// [EditorBrowsable(EditorBrowsableState.Never)]
85-
// [Obsolete("This method is not intended to be called directly by user code")]
85+
// [global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
86+
// [global::System.Obsolete("This method is not intended to be called directly by user code")]
8687
// public static void ValidateAllProperties(<INSTANCE_TYPE> instance)
8788
// {
8889
// <BODY>
8990
// }
9091
// }
9192
// }
9293
var source =
93-
CompilationUnit().AddUsings(
94-
UsingDirective(IdentifierName("System")).WithLeadingTrivia(TriviaList(
94+
CompilationUnit().AddMembers(
95+
NamespaceDeclaration(IdentifierName("Microsoft.Toolkit.Mvvm.ComponentModel.__Internals")).WithLeadingTrivia(TriviaList(
9596
Comment("// Licensed to the .NET Foundation under one or more agreements."),
9697
Comment("// The .NET Foundation licenses this file to you under the MIT license."),
9798
Comment("// See the LICENSE file in the project root for more information."),
98-
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))),
99-
UsingDirective(IdentifierName("System.ComponentModel")),
100-
UsingDirective(IdentifierName("System.Diagnostics")),
101-
UsingDirective(IdentifierName("System.Diagnostics.CodeAnalysis"))).AddMembers(
102-
NamespaceDeclaration(IdentifierName("Microsoft.Toolkit.Mvvm.ComponentModel.__Internals")).AddMembers(
99+
Trivia(PragmaWarningDirectiveTrivia(Token(SyntaxKind.DisableKeyword), true)))).AddMembers(
103100
ClassDeclaration("__ObservableValidatorExtensions").AddModifiers(
104101
Token(SyntaxKind.InternalKeyword),
105102
Token(SyntaxKind.StaticKeyword),
@@ -108,10 +105,10 @@ public void Execute(GeneratorExecutionContext context)
108105
PredefinedType(Token(SyntaxKind.VoidKeyword)),
109106
Identifier("ValidateAllProperties")).AddAttributeLists(
110107
AttributeList(SingletonSeparatedList(
111-
Attribute(IdentifierName("EditorBrowsable")).AddArgumentListArguments(
112-
AttributeArgument(ParseExpression("EditorBrowsableState.Never"))))),
108+
Attribute(IdentifierName("global::System.ComponentModel.EditorBrowsable")).AddArgumentListArguments(
109+
AttributeArgument(ParseExpression("global::System.ComponentModel.EditorBrowsableState.Never"))))),
113110
AttributeList(SingletonSeparatedList(
114-
Attribute(IdentifierName("Obsolete")).AddArgumentListArguments(
111+
Attribute(IdentifierName("global::System.Obsolete")).AddArgumentListArguments(
115112
AttributeArgument(LiteralExpression(
116113
SyntaxKind.StringLiteralExpression,
117114
Literal("This method is not intended to be called directly by user code"))))))).AddModifiers(

0 commit comments

Comments
 (0)