From d0d32f2c56c2d37a0285b8309717d2f7f0914f7b Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Mon, 1 May 2023 21:18:04 +0300 Subject: [PATCH 1/3] fix!: Always use strict search BREAKING CHANGE: Xaml generator now always uses strict search --- .../XamlFileGenerator.Reflection.cs | 24 ++++--------------- .../XamlGenerator/XamlFileGenerator.cs | 2 +- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs index 55f142f2618d..9945e8b80f9a 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs @@ -14,7 +14,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator internal partial class XamlFileGenerator { private Func? _findType; - private Func? _findTypeByXamlType; + private Func? _findTypeByXamlType; private Func? _findPropertyTypeByOwnerSymbol; private Func? _findPropertyTypeByXamlMember; private Func? _findEventType; @@ -34,7 +34,7 @@ private void InitCaches() _findPropertyTypeByXamlMember = Funcs.Create(SourceFindPropertyType).AsLockedMemoized(); _findEventType = Funcs.Create(SourceFindEventType).AsLockedMemoized(); _findPropertyTypeByOwnerSymbol = Funcs.Create(SourceFindPropertyTypeByOwnerSymbol).AsLockedMemoized(); - _findTypeByXamlType = Funcs.Create(SourceFindTypeByXamlType).AsLockedMemoized(); + _findTypeByXamlType = Funcs.Create(SourceFindTypeByXamlType).AsLockedMemoized(); _findLocalizableDeclaredProperties = Funcs.Create(SourceFindLocalizableDeclaredProperties).AsLockedMemoized(); var defaultXmlNamespace = _fileDefinition @@ -592,10 +592,10 @@ private static void ThrowOnErrorSymbol(ISymbol symbol) private INamedTypeSymbol? FindType(string name) => _findType!(name); - private INamedTypeSymbol? FindType(XamlType? type, bool strictSearch = false) - => type != null ? _findTypeByXamlType!(type, strictSearch) : null; + private INamedTypeSymbol? FindType(XamlType? type) + => type != null ? _findTypeByXamlType!(type) : null; - private INamedTypeSymbol? SourceFindTypeByXamlType(XamlType type, bool strictSearch) + private INamedTypeSymbol? SourceFindTypeByXamlType(XamlType type) { if (type != null) { @@ -626,20 +626,6 @@ private static void ThrowOnErrorSymbol(ISymbol symbol) { return namedType; } - - if (!strictSearch) - { - // Then use fuzzy lookup - var ns = _fileDefinition - .Namespaces - // Ensure that prefixless declaration (generally xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation") is considered first, otherwise PreferredXamlNamespace matching can go awry - .OrderByDescending(n => n.Prefix.IsNullOrEmpty()) - .FirstOrDefault(n => n.Namespace == type.PreferredXamlNamespace); - var isKnownNamespace = ns?.Prefix is { Length: > 0 }; - var fullName = isKnownNamespace && ns != null ? ns.Prefix + ":" + type.Name : type.Name; - - return _findType!(fullName); - } } return null; diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index 6320c47934e2..560c49972482 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -4519,7 +4519,7 @@ private bool IsStaticMember(string fullMemberName) { var typeName = fullMemberName.Substring(0, lastDotIndex); return _metadataHelper.FindTypeByFullName(typeName) as INamedTypeSymbol - ?? FindType(new XamlType(_defaultXmlNamespace.Namespace, typeName, new List(), new XamlSchemaContext()), true); + ?? FindType(new XamlType(_defaultXmlNamespace.Namespace, typeName, new List(), new XamlSchemaContext())); } } From d8674daf70e2b58f5482e0ca39d17742a19c25b7 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 2 May 2023 11:07:14 +0300 Subject: [PATCH 2/3] chore: Adjust --- .../XamlGenerator/XamlFileGenerator.Reflection.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs index 9945e8b80f9a..6b36b119e91e 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.Reflection.cs @@ -626,6 +626,16 @@ private static void ThrowOnErrorSymbol(ISymbol symbol) { return namedType; } + + var ns = _fileDefinition + .Namespaces + // Ensure that prefixless declaration (generally xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation") is considered first, otherwise PreferredXamlNamespace matching can go awry + .OrderByDescending(n => n.Prefix.IsNullOrEmpty()) + .FirstOrDefault(n => n.Namespace == type.PreferredXamlNamespace); + if (ns?.Prefix is { Length: > 0 } nsPrefix) + { + return _findType!($"{nsPrefix}:{type.Name}"); + } } return null; From 02967b1f299808fe4a1c68f63d14d70f9ce27239 Mon Sep 17 00:00:00 2001 From: Youssef Victor Date: Tue, 2 May 2023 14:29:43 +0300 Subject: [PATCH 3/3] chore: Adjust --- .../Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs index 560c49972482..f40bb1cb9b1a 100644 --- a/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs +++ b/src/SourceGenerators/Uno.UI.SourceGenerators/XamlGenerator/XamlFileGenerator.cs @@ -6265,7 +6265,7 @@ private IEnumerable EnumerateSubElements(IEnumerable(), new XamlSchemaContext()); + var elementStubType = new XamlType(XamlConstants.BaseXamlNamespace, "ElementStub", new List(), new XamlSchemaContext()); if (hasDataContextMarkup) {