Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Always use strict search #12135

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace Uno.UI.SourceGenerators.XamlGenerator
internal partial class XamlFileGenerator
{
private Func<string, INamedTypeSymbol?>? _findType;
private Func<XamlType, bool, INamedTypeSymbol?>? _findTypeByXamlType;
private Func<XamlType, INamedTypeSymbol?>? _findTypeByXamlType;
private Func<INamedTypeSymbol?, string, INamedTypeSymbol?>? _findPropertyTypeByOwnerSymbol;
private Func<XamlMember, INamedTypeSymbol?>? _findPropertyTypeByXamlMember;
private Func<XamlMember, IEventSymbol?>? _findEventType;
Expand All @@ -34,7 +34,7 @@ private void InitCaches()
_findPropertyTypeByXamlMember = Funcs.Create<XamlMember, INamedTypeSymbol?>(SourceFindPropertyType).AsLockedMemoized();
_findEventType = Funcs.Create<XamlMember, IEventSymbol?>(SourceFindEventType).AsLockedMemoized();
_findPropertyTypeByOwnerSymbol = Funcs.Create<INamedTypeSymbol?, string, INamedTypeSymbol?>(SourceFindPropertyTypeByOwnerSymbol).AsLockedMemoized();
_findTypeByXamlType = Funcs.Create<XamlType, bool, INamedTypeSymbol?>(SourceFindTypeByXamlType).AsLockedMemoized();
_findTypeByXamlType = Funcs.Create<XamlType, INamedTypeSymbol?>(SourceFindTypeByXamlType).AsLockedMemoized();
_findLocalizableDeclaredProperties = Funcs.Create<INamedTypeSymbol, string[]>(SourceFindLocalizableDeclaredProperties).AsLockedMemoized();

var defaultXmlNamespace = _fileDefinition
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -627,18 +627,14 @@ private static void ThrowOnErrorSymbol(ISymbol symbol)
return namedType;
}

if (!strictSearch)
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)
{
// 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 _findType!($"{nsPrefix}:{type.Name}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<XamlType>(), new XamlSchemaContext()), true);
?? FindType(new XamlType(_defaultXmlNamespace.Namespace, typeName, new List<XamlType>(), new XamlSchemaContext()));
}
}

Expand Down Expand Up @@ -6265,7 +6265,7 @@ private IEnumerable<XamlObjectDefinition> EnumerateSubElements(IEnumerable<XamlO
string closureName;
using (var innerWriter = CreateApplyBlock(writer, Generation.ElementStubSymbol.Value, out closureName))
{
var elementStubType = new XamlType("", "ElementStub", new List<XamlType>(), new XamlSchemaContext());
var elementStubType = new XamlType(XamlConstants.BaseXamlNamespace, "ElementStub", new List<XamlType>(), new XamlSchemaContext());

if (hasDataContextMarkup)
{
Expand Down