Skip to content

Commit

Permalink
fix: Fix regression in code gen
Browse files Browse the repository at this point in the history
  • Loading branch information
dr1rrb committed Jan 9, 2025
1 parent 4094050 commit ad93732
Show file tree
Hide file tree
Showing 7 changed files with 363 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,16 @@ public MainPage()

await test.RunAsync();
}

[TestMethod]
public async Task When_Nested_With_Sibling_Ref_And_Event()
{
var test = new TestSetup(
xamlFileName: "ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml",
subFolder: Path.Combine("SourceGenerators", "Uno.UI.SourceGenerators.Tests", "XamlCodeGeneratorTests", "TestCases"))
{
};

await Verify.AssertXamlGenerator(test);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// <autogenerated />
namespace MyProject
{
/// <summary>
/// Contains all the static resources defined for the application
/// </summary>
public sealed partial class GlobalStaticResources
{
static bool _initialized;
private static bool _stylesRegistered;
private static bool _dictionariesRegistered;
internal static global::Uno.UI.Xaml.XamlParseContext __ParseContext_ { get; } = new global::Uno.UI.Xaml.XamlParseContext()
{
AssemblyName = "TestProject",
}
;

static GlobalStaticResources()
{
Initialize();
}
public static void Initialize()
{
if (!_initialized)
{
_initialized = true;
global::Uno.UI.GlobalStaticResources.Initialize();
global::Uno.UI.GlobalStaticResources.RegisterDefaultStyles();
global::Uno.UI.GlobalStaticResources.RegisterResourceDictionariesBySource();
}
}
public static void RegisterDefaultStyles()
{
if(!_stylesRegistered)
{
_stylesRegistered = true;
RegisterDefaultStyles_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20();
}
}
// Register ResourceDictionaries using ms-appx:/// syntax, this is called for external resources
public static void RegisterResourceDictionariesBySource()
{
if(!_dictionariesRegistered)
{
_dictionariesRegistered = true;
}
}
// Register ResourceDictionaries using ms-resource:/// syntax, this is called for local resources
internal static void RegisterResourceDictionariesBySourceLocal()
{
}
static partial void RegisterDefaultStyles_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20();

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// <auto-generated />
[assembly: global::System.Reflection.AssemblyMetadata("UnoHasLocalizationResources", "False")]
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
// <autogenerated />
#pragma warning disable CS0114
#pragma warning disable CS0108
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using Uno.UI;
using Uno.UI.Xaml;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Documents;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Media.Animation;
using Microsoft.UI.Xaml.Shapes;
using Windows.UI.Text;
using Uno.Extensions;
using Uno;
using Uno.UI.Helpers;
using Uno.UI.Helpers.Xaml;
using MyProject;

#if __ANDROID__
using _View = Android.Views.View;
#elif __IOS__
using _View = UIKit.UIView;
#elif __MACOS__
using _View = AppKit.NSView;
#else
using _View = Microsoft.UI.Xaml.UIElement;
#endif

namespace Uno.UI.Tests.Given_ResourceDictionary
{
partial class When_Nested_With_Sibling_Ref_And_Event : global::Microsoft.UI.Xaml.Controls.Page
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_prefix_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20 = "ms-appx:///TestProject/";
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20 = "ms-appx:///TestProject/";
private global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
private void InitializeComponent()
{
NameScope.SetNameScope(this, __nameScope);
var __that = this;
base.IsParsing = true;
Resources[
"RootResource"
] =
new global::Uno.UI.Xaml.WeakResourceInitializer(this, __ResourceOwner_1 =>
{
return
new global::Microsoft.UI.Xaml.DataTemplate(__ResourceOwner_1, (__owner) => new _ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_UnoUITestsGiven_ResourceDictionaryWhen_Nested_With_Sibling_Ref_And_EventSC0().Build(__owner)
) ;
}
)
;
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 1:2)
;

this
.ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply((ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions.XamlApplyHandler0)(__p1 =>
{
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 1:2)

// WARNING Property __p1.base does not exist on {http://schemas.microsoft.com/winfx/2006/xaml/presentation}Page, the namespace is http://www.w3.org/XML/1998/namespace. This error was considered irrelevant by the XamlFileGenerator
}
))
.ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply((ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions.XamlApplyHandler0)(__p1 =>
{
// Class Uno.UI.Tests.Given_ResourceDictionary.When_Nested_With_Sibling_Ref_And_Event
global::Uno.UI.FrameworkElementHelper.SetBaseUri(__p1, __baseUri_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20);
__p1.CreationComplete();
}
))
;
OnInitializeCompleted();

}
partial void OnInitializeCompleted();
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2026")]
[global::System.Diagnostics.CodeAnalysis.UnconditionalSuppressMessage("Trimming", "IL2111")]
private class _ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_UnoUITestsGiven_ResourceDictionaryWhen_Nested_With_Sibling_Ref_And_EventSC0
{
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_prefix_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20 = "ms-appx:///TestProject/";
[global::System.ComponentModel.EditorBrowsable(global::System.ComponentModel.EditorBrowsableState.Never)]
private const string __baseUri_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20 = "ms-appx:///TestProject/";
global::Microsoft.UI.Xaml.NameScope __nameScope = new global::Microsoft.UI.Xaml.NameScope();
global::System.Object __ResourceOwner_1;
_View __rootInstance = null;
public _View Build(object __ResourceOwner_1)
{
var __that = this;
this.__ResourceOwner_1 = __ResourceOwner_1;
this.__rootInstance =
new global::Microsoft.UI.Xaml.Controls.Border
{
IsParsing = true,
Resources = {
[
"SiblingResource"
] =
new global::Microsoft.UI.Xaml.Controls.FontIconSource
{
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 14:7)
}
,
[
"FailingResource"
] =
new global::Uno.UI.Xaml.WeakResourceInitializer(__ResourceOwner_1, __ResourceOwner_2 =>
{
return
new global::Microsoft.UI.Xaml.Controls.SwipeItems
{
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 15:7)
}
.ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply((ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions.XamlApplyHandler1)(__p1 =>
{
__p1.Add(
new global::Microsoft.UI.Xaml.Controls.SwipeItem
{
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 16:8)
}
.ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply((ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions.XamlApplyHandler2)(__p1 =>
{
/* _isTopLevelDictionary:False */
__that._component_0 = __p1;
global::Microsoft.UI.Xaml.NameScope.SetNameScope(__that._component_0, __nameScope);
global::Uno.UI.ResourceResolverSingleton.Instance.ApplyResource(__p1, global::Microsoft.UI.Xaml.Controls.SwipeItem.IconSourceProperty, "SiblingResource", isThemeResourceExtension: false, isHotReloadSupported: false, context: global::MyProject.GlobalStaticResources.__ParseContext_);
var Invoked_AnEventHandler_That = (__ResourceOwner_2 as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference;
/* second level */ __p1.Invoked += (AnEventHandler_sender,AnEventHandler_args) => (Invoked_AnEventHandler_That.Target as global::Uno.UI.Tests.Given_ResourceDictionary.When_Nested_With_Sibling_Ref_And_Event)?.AnEventHandler(AnEventHandler_sender,AnEventHandler_args);
}
))
);
}
))
;
}
)
,
},
// Source 0\ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event.xaml (Line 12:5)
}
.ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply((ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions.XamlApplyHandler3)(__p1 =>
{
/* _isTopLevelDictionary:False */
__that._component_1 = __p1;
global::Uno.UI.FrameworkElementHelper.SetBaseUri(__p1, __baseUri_ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20);
__p1.CreationComplete();
}
))
;
if (__rootInstance is FrameworkElement __fe)
{
__fe.Loading += __UpdateBindingsAndResources;
}
if (__rootInstance is DependencyObject d)
{
if (global::Microsoft.UI.Xaml.NameScope.GetNameScope(d) == null)
{
global::Microsoft.UI.Xaml.NameScope.SetNameScope(d, __nameScope);
__nameScope.Owner = d;
}
global::Uno.UI.FrameworkElementHelper.AddObjectReference(d, this);
}
return __rootInstance;
}
private global::Microsoft.UI.Xaml.Markup.ComponentHolder _component_0_Holder = new global::Microsoft.UI.Xaml.Markup.ComponentHolder(isWeak: true);
private global::Microsoft.UI.Xaml.Controls.SwipeItem _component_0
{
get
{
return (global::Microsoft.UI.Xaml.Controls.SwipeItem)_component_0_Holder.Instance;
}
set
{
_component_0_Holder.Instance = value;
}
}
private global::Microsoft.UI.Xaml.Markup.ComponentHolder _component_1_Holder = new global::Microsoft.UI.Xaml.Markup.ComponentHolder(isWeak: true);
private global::Microsoft.UI.Xaml.Controls.Border _component_1
{
get
{
return (global::Microsoft.UI.Xaml.Controls.Border)_component_1_Holder.Instance;
}
set
{
_component_1_Holder.Instance = value;
}
}
private void __UpdateBindingsAndResources(global::Microsoft.UI.Xaml.FrameworkElement s, object e)
{
var owner = this;
_component_0.UpdateResourceBindings();
}
}
}
}
namespace MyProject
{
static class ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20XamlApplyExtensions
{
public delegate void XamlApplyHandler0(global::Microsoft.UI.Xaml.Controls.Page instance);
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static global::Microsoft.UI.Xaml.Controls.Page ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply(this global::Microsoft.UI.Xaml.Controls.Page instance, XamlApplyHandler0 handler)
{
handler(instance);
return instance;
}
public delegate void XamlApplyHandler1(global::Microsoft.UI.Xaml.Controls.SwipeItems instance);
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static global::Microsoft.UI.Xaml.Controls.SwipeItems ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply(this global::Microsoft.UI.Xaml.Controls.SwipeItems instance, XamlApplyHandler1 handler)
{
handler(instance);
return instance;
}
public delegate void XamlApplyHandler2(global::Microsoft.UI.Xaml.Controls.SwipeItem instance);
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static global::Microsoft.UI.Xaml.Controls.SwipeItem ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply(this global::Microsoft.UI.Xaml.Controls.SwipeItem instance, XamlApplyHandler2 handler)
{
handler(instance);
return instance;
}
public delegate void XamlApplyHandler3(global::Microsoft.UI.Xaml.Controls.Border instance);
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
public static global::Microsoft.UI.Xaml.Controls.Border ResourceDictionary_When_Nested_With_Sibling_Ref_And_Event_6d62c5ee15120ed189e095faf6d37e20_XamlApply(this global::Microsoft.UI.Xaml.Controls.Border instance, XamlApplyHandler3 handler)
{
handler(instance);
return instance;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<Page
x:Class="Uno.UI.Tests.Given_ResourceDictionary.When_Nested_With_Sibling_Ref_And_Event"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="using:Uno.UI.Tests.Windows_UI_XAML_Controls.GridTests.Controls"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>
<DataTemplate x:Key="RootResource">
<Border>
<Border.Resources>
<FontIconSource x:Key="SiblingResource" />
<SwipeItems x:Key="FailingResource">
<SwipeItem IconSource="{StaticResource SiblingResource}" Invoked="AnEventHandler"/>
</SwipeItems>
</Border.Resources>
</Border>
</DataTemplate>
</Page.Resources>
</Page>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;

namespace Uno.UI.Tests.Given_ResourceDictionary
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class When_Nested_With_Sibling_Ref_And_Event : Page
{
public When_Nested_With_Sibling_Ref_And_Event()
{
this.InitializeComponent();
}

private void AnEventHandler(SwipeItem sender, SwipeItemInvokedEventArgs args)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3756,8 +3756,7 @@ IMethodSymbol FindTargetMethodSymbol(INamedTypeSymbol? sourceType)
// use the WeakReferenceProvider to get a self reference to avoid adding the cost of the
// creation of a WeakReference.
//
var thatEventSource = eventSource != "__that" ? "__that." + eventSource : eventSource;
writer.AppendLineIndented($"var {member.Member.Name}_{sanitizedMemberValue}_That = ({thatEventSource} as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference;");
writer.AppendLineIndented($"var {member.Member.Name}_{sanitizedMemberValue}_That = ({eventSource} as global::Uno.UI.DataBinding.IWeakReferenceProvider).WeakReference;");

writer.AppendLineIndented($"/* second level */ {closureName}.{member.Member.Name} += ({parms}) => ({member.Member.Name}_{sanitizedMemberValue}_That.Target as {_xClassName})?.{member.Value}({parms});");
}
Expand Down

0 comments on commit ad93732

Please sign in to comment.