Skip to content

Commit

Permalink
Fix for OAPH nullability for reference types
Browse files Browse the repository at this point in the history
Added Nested Project test to prove inheritance can operate
  • Loading branch information
ChrisPulman committed Nov 9, 2024
1 parent 954ab78 commit 370c3a5
Show file tree
Hide file tree
Showing 9 changed files with 136 additions and 5 deletions.
18 changes: 18 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute.Nested1/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace SGReactiveUI.SourceGenerators.Execute.Nested1;

/// <summary>
/// Class1.
/// </summary>
public partial class Class1 : ReactiveObject
{
[Reactive]
private string? _property1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="ReactiveUI" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute.Nested2/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace SGReactiveUI.SourceGenerators.Execute.Nested2;

/// <summary>
/// Class1.
/// </summary>
public partial class Class1 : ReactiveObject
{
[Reactive]
private string? _property1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Execute.Nested1\ReactiveUI.SourceGenerators.Execute.Nested1.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute.Nested3/Class1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) 2024 .NET Foundation and Contributors. All rights reserved.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;
using ReactiveUI.SourceGenerators;

namespace SGReactiveUI.SourceGenerators.Execute.Nested3;

/// <summary>
/// Class1.
/// </summary>
public partial class Class1 : ReactiveObject
{
[Reactive]
private string? _property1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
<LangVersion>12.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\ReactiveUI.SourceGenerators\ReactiveUI.SourceGenerators.csproj" OutputItemType="Analyzer" ReferenceOutputAssembly="false" PrivateAssets="all" />
<ProjectReference Include="..\ReactiveUI.SourceGenerators.Execute.Nested2\ReactiveUI.SourceGenerators.Execute.Nested2.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,12 @@ public TestViewModel()
/// </summary>
public ViewModelActivator Activator { get; } = new();

[ObservableAsProperty]
private IObservable<object> ReferenceTypeObservable { get; }

[ObservableAsProperty]
private IObservable<object?> NullableReferenceTypeObservable { get; }

/// <summary>
/// Gets observables as property test.
/// </summary>
Expand Down
26 changes: 25 additions & 1 deletion src/ReactiveUI.SourceGenerators.sln
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
# 17
VisualStudioVersion = 17.10.35027.167
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SolutionConfig", "SolutionConfig", "{F29AF2F3-DEC8-58BC-043A-1447862C832D}"
Expand All @@ -26,6 +26,14 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "TestLibs", "TestLibs", "{B8
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ReactiveUI.SourceGenerators.Analyzers.CodeFixes", "ReactiveUI.SourceGenerators.Analyzers.CodeFixes\ReactiveUI.SourceGenerators.Analyzers.CodeFixes.csproj", "{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested1", "ReactiveUI.SourceGenerators.Execute.Nested1\ReactiveUI.SourceGenerators.Execute.Nested1.csproj", "{A4971B7D-E35F-4891-BF32-BE911AE86900}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested2", "ReactiveUI.SourceGenerators.Execute.Nested2\ReactiveUI.SourceGenerators.Execute.Nested2.csproj", "{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReactiveUI.SourceGenerators.Execute.Nested3", "ReactiveUI.SourceGenerators.Execute.Nested3\ReactiveUI.SourceGenerators.Execute.Nested3.csproj", "{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "NestedTest", "NestedTest", "{CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -52,13 +60,29 @@ Global
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BD4FADD9-C0E5-46E9-906E-01B04CC856B5}.Release|Any CPU.Build.0 = Release|Any CPU
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A4971B7D-E35F-4891-BF32-BE911AE86900}.Release|Any CPU.Build.0 = Release|Any CPU
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A}.Release|Any CPU.Build.0 = Release|Any CPU
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{76D5AC8C-4935-3E4B-BD12-71FAEC2B9A9D} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
{849CACF4-B85F-47B5-84B3-7C94DE864E7E} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
{A4971B7D-E35F-4891-BF32-BE911AE86900} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
{CB36161E-8F9E-48B5-8CE0-AC130A73BD2A} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
{B42F683D-91D8-4378-9DFE-EC55DB0FE43A} = {CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16}
{CAFBD27B-5078-4A0C-A4E9-19DCF2A7DF16} = {B86ED9C1-AFFB-4854-AD80-F4B4050CAD0A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {173F891B-86A2-4226-B563-A7318CE0E2EC}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public sealed partial class ObservableAsPropertyGenerator

var observableType = methodSymbol.ReturnType is not INamedTypeSymbol typeSymbol
? string.Empty
: typeSymbol.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
: typeSymbol.TypeArguments[0].GetFullyQualifiedNameWithNullabilityAnnotations();

// Get the hierarchy info for the target symbol, and try to gather the property info
hierarchy = HierarchyInfo.From(methodSymbol.ContainingType);
Expand All @@ -82,7 +82,7 @@ public sealed partial class ObservableAsPropertyGenerator
targetInfo.TargetVisibility,
targetInfo.TargetType,
methodSymbol.Name,
methodSymbol.ReturnType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
methodSymbol.ReturnType.GetFullyQualifiedNameWithNullabilityAnnotations(),
methodSymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
propertyName ?? (methodSymbol.Name + "Property"),
observableType,
Expand All @@ -109,7 +109,7 @@ public sealed partial class ObservableAsPropertyGenerator

var observableType = propertySymbol.Type is not INamedTypeSymbol typeSymbol
? string.Empty
: typeSymbol.TypeArguments[0].ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
: typeSymbol.TypeArguments[0].GetFullyQualifiedNameWithNullabilityAnnotations();

// Get the hierarchy info for the target symbol, and try to gather the property info
hierarchy = HierarchyInfo.From(propertySymbol.ContainingType);
Expand All @@ -127,7 +127,7 @@ public sealed partial class ObservableAsPropertyGenerator
targetInfo.TargetVisibility,
targetInfo.TargetType,
propertySymbol.Name,
propertySymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations(),
propertySymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
propertyName ?? (propertySymbol.Name + "Property"),
observableType,
Expand Down

0 comments on commit 370c3a5

Please sign in to comment.