-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
housekeeping: Diagnostics and Refactorings (#6)
* NameDirectiveTransformer.cs * Build-time diagnostics
- Loading branch information
1 parent
b45c450
commit e3490c6
Showing
7 changed files
with
122 additions
and
68 deletions.
There are no files selected for viewing
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
54 changes: 0 additions & 54 deletions
54
src/XamlNameReferenceGenerator/Infrastructure/MiniNamedControlCollector.cs
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
src/XamlNameReferenceGenerator/Infrastructure/NameDirectiveTransformer.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using XamlX; | ||
using XamlX.Ast; | ||
using XamlX.Transform; | ||
|
||
namespace XamlNameReferenceGenerator.Infrastructure | ||
{ | ||
public class NameDirectiveTransformer : IXamlAstTransformer | ||
{ | ||
public IXamlAstNode Transform(AstTransformationContext context, IXamlAstNode node) | ||
{ | ||
if (node is XamlAstObjectNode objectNode) | ||
{ | ||
for (var index = 0; index < objectNode.Children.Count; index++) | ||
{ | ||
var child = objectNode.Children[index]; | ||
if (child is XamlAstXmlDirective directive && | ||
directive.Namespace == XamlNamespaces.Xaml2006 && | ||
directive.Name == "Name") | ||
objectNode.Children[index] = new XamlAstXamlPropertyValueNode( | ||
directive, | ||
new XamlAstNamePropertyReference(directive, objectNode.Type, "Name", objectNode.Type), | ||
directive.Values); | ||
} | ||
} | ||
|
||
return node; | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/XamlNameReferenceGenerator/Infrastructure/NamedControlCollector.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System.Collections.Generic; | ||
using XamlX.Ast; | ||
|
||
namespace XamlNameReferenceGenerator.Infrastructure | ||
{ | ||
internal sealed class NamedControlCollector : IXamlAstVisitor | ||
{ | ||
private readonly List<(string TypeName, string Name)> _items = new List<(string TypeName, string Name)>(); | ||
|
||
public IReadOnlyList<(string TypeName, string Name)> Controls => _items; | ||
|
||
public IXamlAstNode Visit(IXamlAstNode node) | ||
{ | ||
if (node is XamlAstConstructableObjectNode constructableObjectNode) | ||
{ | ||
foreach (var child in constructableObjectNode.Children) | ||
{ | ||
if (child is XamlAstXamlPropertyValueNode propertyValueNode && | ||
propertyValueNode.Property is XamlAstClrProperty clrProperty && | ||
clrProperty.Name == "Name" && | ||
propertyValueNode.Values.Count > 0 && | ||
propertyValueNode.Values[0] is XamlAstTextNode text) | ||
{ | ||
var clrType = constructableObjectNode.Type.GetClrType(); | ||
var typeNamePair = ($@"{clrType.Namespace}.{clrType.Name}", text.Text); | ||
|
||
if (!_items.Contains(typeNamePair)) | ||
{ | ||
_items.Add(typeNamePair); | ||
} | ||
} | ||
} | ||
|
||
return node; | ||
} | ||
|
||
return node; | ||
} | ||
|
||
public void Push(IXamlAstNode node) { } | ||
|
||
public void Pop() { } | ||
} | ||
} |
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
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
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