Skip to content

Commit

Permalink
fix!: Always use strict search (#12135)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Xaml generator now always uses strict search

GitHub Issue (If applicable): Part of #8339
<!-- Link to relevant GitHub issue if applicable. All PRs should be
associated with an issue (GitHub issue or internal), unless the change
is documentation related. -->

## PR Type

What kind of change does this PR introduce?
<!-- Please uncomment one or more that apply to this PR

- Bugfix
- Feature
- Code style update (formatting)
- Refactoring (no functional changes, no api changes)
- Build or CI related changes
- Documentation content changes
- Project automation
- Other... Please describe:

-->

## What is the current behavior?

<!-- Please describe the current behavior that you are modifying, or
link to a relevant issue. -->


## What is the new behavior?

<!-- Please describe the new behavior after your modifications. -->


## PR Checklist

Please check if your PR fulfills the following requirements:

- [ ] Docs have been added/updated which fit [documentation
template](https://github.com/unoplatform/uno/blob/master/doc/.feature-template.md)
(for bug fixes / features)
- [ ] [Unit Tests and/or UI
Tests](https://github.com/unoplatform/uno/blob/master/doc/articles/uno-development/working-with-the-samples-apps.md)
for the changes have been added (for bug fixes / features) (if
applicable)
- [ ] Validated PR `Screenshots Compare Test Run` results.
- [ ] Contains **NO** breaking changes
- [ ] Associated with an issue (GitHub or internal) and uses the
[automatic close
keywords](https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue).
- [ ] Commits must be following the [Conventional
Commits](https://www.conventionalcommits.org/en/v1.0.0/#summary)
specification.

<!-- If this PR contains a breaking change, please describe the impact
and migration path for existing applications below.
     Please note that breaking changes are likely to be rejected -->

## Other information

<!-- Please provide any additional information if necessary -->

Internal Issue (If applicable):
<!-- Link to relevant internal issue if applicable. All PRs should be
associated with an issue (GitHub issue or internal) -->
  • Loading branch information
jeromelaban authored May 3, 2023
2 parents cbd32bd + 02967b1 commit 74e05ab
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 18 deletions.
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

0 comments on commit 74e05ab

Please sign in to comment.