This repository was archived by the owner on Sep 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
Avoid globally qualifying user defined types #69
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
55 changes: 55 additions & 0 deletions
55
...ntDesignTimeCodeGenerationTest/GenericComponent_NonPrimitiveType/TestComponent.codegen.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // <auto-generated/> | ||
| #pragma warning disable 1591 | ||
| namespace Test | ||
| { | ||
| #line hidden | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Components; | ||
| public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase | ||
| { | ||
| #pragma warning disable 219 | ||
| private void __RazorDirectiveTokenHelpers__() { | ||
| } | ||
| #pragma warning restore 219 | ||
| #pragma warning disable 0414 | ||
| private static System.Object __o = null; | ||
| #pragma warning restore 0414 | ||
| #pragma warning disable 1998 | ||
| protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) | ||
| { | ||
| __o = typeof( | ||
| #nullable restore | ||
| #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" | ||
| CustomType | ||
|
|
||
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
| ); | ||
| __o = global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<CustomType>( | ||
| #nullable restore | ||
| #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" | ||
| new CustomType() | ||
|
|
||
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
| ); | ||
| __builder.AddAttribute(-1, "ChildContent", (global::Microsoft.AspNetCore.Components.RenderFragment)((__builder2) => { | ||
| } | ||
| )); | ||
| #nullable restore | ||
| #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" | ||
| __o = typeof(global::Test.MyComponent<>); | ||
|
|
||
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
| } | ||
| #pragma warning restore 1998 | ||
| } | ||
| } | ||
| #pragma warning restore 1591 |
21 changes: 21 additions & 0 deletions
21
...ponentDesignTimeCodeGenerationTest/GenericComponent_NonPrimitiveType/TestComponent.ir.txt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| Document - | ||
| NamespaceDeclaration - - Test | ||
| UsingDirective - (3:1,1 [12] ) - System | ||
| UsingDirective - (18:2,1 [32] ) - System.Collections.Generic | ||
| UsingDirective - (53:3,1 [17] ) - System.Linq | ||
| UsingDirective - (73:4,1 [28] ) - System.Threading.Tasks | ||
| UsingDirective - (104:5,1 [37] ) - Microsoft.AspNetCore.Components | ||
| ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - | ||
| DesignTimeDirective - | ||
| CSharpCode - | ||
| IntermediateToken - - CSharp - #pragma warning disable 0414 | ||
| CSharpCode - | ||
| IntermediateToken - - CSharp - private static System.Object __o = null; | ||
| CSharpCode - | ||
| IntermediateToken - - CSharp - #pragma warning restore 0414 | ||
| MethodDeclaration - - protected override - void - BuildRenderTree | ||
| Component - (0:0,0 [57] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent | ||
| ComponentTypeArgument - (20:0,20 [10] x:\dir\subdir\Test\TestComponent.cshtml) - TItem | ||
| LazyIntermediateToken - (20:0,20 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - CustomType | ||
| ComponentAttribute - (38:0,38 [16] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item - AttributeStructure.DoubleQuotes | ||
| LazyIntermediateToken - (38:0,38 [16] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new CustomType() |
10 changes: 10 additions & 0 deletions
10
...DesignTimeCodeGenerationTest/GenericComponent_NonPrimitiveType/TestComponent.mappings.txt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| Source Location: (20:0,20 [10] x:\dir\subdir\Test\TestComponent.cshtml) | ||
| |CustomType| | ||
| Generated Location: (915:25,20 [10] ) | ||
| |CustomType| | ||
|
|
||
| Source Location: (38:0,38 [16] x:\dir\subdir\Test\TestComponent.cshtml) | ||
| |new CustomType()| | ||
| Generated Location: (1215:34,38 [16] ) | ||
| |new CustomType()| | ||
|
|
31 changes: 31 additions & 0 deletions
31
...onentRuntimeCodeGenerationTest/GenericComponent_NonPrimitiveType/TestComponent.codegen.cs
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| // <auto-generated/> | ||
| #pragma warning disable 1591 | ||
| namespace Test | ||
| { | ||
| #line hidden | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Components; | ||
| public partial class TestComponent : global::Microsoft.AspNetCore.Components.ComponentBase | ||
| { | ||
| #pragma warning disable 1998 | ||
| protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) | ||
| { | ||
| __builder.OpenComponent<global::Test.MyComponent<CustomType>>(0); | ||
| __builder.AddAttribute(1, "Item", global::Microsoft.AspNetCore.Components.CompilerServices.RuntimeHelpers.TypeCheck<CustomType>( | ||
| #nullable restore | ||
| #line 1 "x:\dir\subdir\Test\TestComponent.cshtml" | ||
| new CustomType() | ||
|
|
||
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
| )); | ||
| __builder.CloseComponent(); | ||
| } | ||
| #pragma warning restore 1998 | ||
| } | ||
| } | ||
| #pragma warning restore 1591 |
14 changes: 14 additions & 0 deletions
14
...ComponentRuntimeCodeGenerationTest/GenericComponent_NonPrimitiveType/TestComponent.ir.txt
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| Document - | ||
| NamespaceDeclaration - - Test | ||
| UsingDirective - (3:1,1 [14] ) - System | ||
| UsingDirective - (18:2,1 [34] ) - System.Collections.Generic | ||
| UsingDirective - (53:3,1 [19] ) - System.Linq | ||
| UsingDirective - (73:4,1 [30] ) - System.Threading.Tasks | ||
| UsingDirective - (104:5,1 [39] ) - Microsoft.AspNetCore.Components | ||
| ClassDeclaration - - public partial - TestComponent - global::Microsoft.AspNetCore.Components.ComponentBase - | ||
| MethodDeclaration - - protected override - void - BuildRenderTree | ||
| Component - (0:0,0 [57] x:\dir\subdir\Test\TestComponent.cshtml) - MyComponent | ||
| ComponentTypeArgument - (20:0,20 [10] x:\dir\subdir\Test\TestComponent.cshtml) - TItem | ||
| LazyIntermediateToken - (20:0,20 [10] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - CustomType | ||
| ComponentAttribute - (38:0,38 [16] x:\dir\subdir\Test\TestComponent.cshtml) - Item - Item - AttributeStructure.DoubleQuotes | ||
| LazyIntermediateToken - (38:0,38 [16] x:\dir\subdir\Test\TestComponent.cshtml) - CSharp - new CustomType() |
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -181,7 +181,7 @@ private void CreateProperty(TagHelperDescriptorBuilder builder, IPropertySymbol | |
| pb.TypeName = property.Type.ToDisplayString(FullNameTypeDisplayFormat); | ||
| pb.SetPropertyName(property.Name); | ||
| pb.IsEditorRequired = property.GetAttributes().Any(a => a.AttributeClass.ToDisplayString() == "Microsoft.AspNetCore.Components.EditorRequiredAttribute"); | ||
|
|
||
| pb.SetGloballyQualifiedTypeName(property.Type.ToDisplayString(GloballyQualifiedFullNameTypeDisplayFormat)); | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The key is here, where we capture the globally qualified type name for the type. This comes from the symbol, and we re-use it later on. |
||
| if (kind == PropertyKind.Enum) | ||
| { | ||
| pb.IsEnum = true; | ||
|
|
||
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,21 @@ public override SyntaxNode VisitQualifiedName(QualifiedNameSyntax node) | |
| node = (QualifiedNameSyntax)base.VisitQualifiedName(node); | ||
|
|
||
| // Rewriting these is complicated, best to just tostring and parse again. | ||
| return SyntaxFactory.ParseTypeName("global::" + node.ToString()); | ||
| return SyntaxFactory.ParseTypeName(IsGloballyQualified(node) ? node.ToString() : "global::" + node.ToString()); | ||
javiercn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| static bool IsGloballyQualified(QualifiedNameSyntax node) | ||
| { | ||
| var candidate = node; | ||
| while (candidate != null) | ||
| { | ||
| if (candidate.Left is AliasQualifiedNameSyntax) | ||
| { | ||
| return true; | ||
| } | ||
| candidate = candidate.Left as QualifiedNameSyntax; | ||
| } | ||
| return false; | ||
| } | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This rewriter needs to account for the fact that the types might already be globally qualified |
||
| } | ||
|
|
||
| public override SyntaxNode VisitIdentifierName(IdentifierNameSyntax node) | ||
|
|
||
This file contains hidden or 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
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.
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.
We use this metadata to signal that we replaced something like TItem with potential user input, like MyType (which we can't qualify) to avoid prepending
global::incorrectly.