Skip to content
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 @@ -7,7 +7,7 @@

namespace TestNs
{
/// <summary>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm guessing the offset is just caused by a """ raw string literal, where the first line is not aligned with the ending quotes.

/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TestNs
{
/// <summary>
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TestNs
{
/// <summary>
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TestNs
{
/// <summary>
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TestNs1
{
/// <summary>
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace TestNs2
{
/// <summary>
/// <summary>
/// Partial class for the TestVM which contains ReactiveUI Reactive property initialization.
/// </summary>
public partial class TestVM
Expand Down
66 changes: 39 additions & 27 deletions src/ReactiveUI.SourceGenerators.Execute/TestViewModel3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,43 @@ public partial class TestViewModel3 : ReactiveObject
[Reactive]
private float _testVM3Property;

/////// <summary>
/////// TestInnerClass.
/////// </summary>
////public partial class TestInnerClass1 : ReactiveObject
////{
//// [Reactive]
//// private int _testInner1;
////}

/////// <summary>
/////// TestInnerClass.
/////// </summary>
////public partial class TestInnerClass2 : ReactiveObject
////{
//// [Reactive]
//// private int _testInner2;

//// /// <summary>
//// /// TestInnerClass4.
//// /// </summary>
//// /// <seealso cref="ReactiveUI.ReactiveObject" />
//// public partial class TestInnerClass3 : ReactiveObject
//// {
//// [Reactive]
//// private int _testInner3;
//// }
////}
[Reactive]
private float _testVM3Property2;

/// <summary>
/// TestInnerClass.
/// </summary>
public partial class TestInnerClass1 : ReactiveObject
{
[Reactive]
private int _testInner1;

[Reactive]
private int _testInner11;
}

/// <summary>
/// TestInnerClass.
/// </summary>
public partial class TestInnerClass2 : ReactiveObject
{
[Reactive]
private int _testInner2;

[Reactive]
private int _testInner22;

/// <summary>
/// TestInnerClass4.
/// </summary>
/// <seealso cref="ReactiveUI.ReactiveObject" />
public partial class TestInnerClass3 : ReactiveObject
{
[Reactive]
private int _testInner3;

[Reactive]
private int _testInner33;
}
}
}
58 changes: 56 additions & 2 deletions src/ReactiveUI.SourceGenerators/Core/Models/TargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// 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 System.Collections.Generic;
using Microsoft.CodeAnalysis;
using ReactiveUI.SourceGenerators.Extensions;
using ReactiveUI.SourceGenerators.Helpers;
Expand All @@ -15,7 +16,8 @@ internal sealed partial record TargetInfo(
string TargetNamespace,
string TargetNamespaceWithNamespace,
string TargetVisibility,
string TargetType)
string TargetType,
TargetInfo? ParentInfo)
{
public static TargetInfo From(INamedTypeSymbol namedTypeSymbol)
{
Expand All @@ -26,12 +28,64 @@ public static TargetInfo From(INamedTypeSymbol namedTypeSymbol)
var targetAccessibility = namedTypeSymbol.GetAccessibilityString();
var targetType = namedTypeSymbol.GetTypeString();

var parentInfo = namedTypeSymbol.ContainingType is not null
? From(namedTypeSymbol.ContainingType)
: null;

return new(
targetHintName,
targetName,
targetNamespace,
targetNameWithNamespace,
targetAccessibility,
targetType);
targetType,
parentInfo);
}

public static void GetParentClasses(ref List<string> parentClassDeclarations, TargetInfo? targetInfo)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't need to be ref does it

{
if (targetInfo is not null)
{
var parentClassDeclaration = $"{targetInfo.TargetVisibility} partial {targetInfo.TargetType} {targetInfo.TargetName}";

// Add the parent class declaration if it does not exist in the list
if (!parentClassDeclarations.Contains(parentClassDeclaration))
{
parentClassDeclarations.Add(parentClassDeclaration);
}

if (targetInfo.ParentInfo is not null)
{
// Recursively get the parent classes
GetParentClasses(ref parentClassDeclarations, targetInfo.ParentInfo);
}
}
}

public static string GenerateParentClassDeclarations(ref List<string> parentClassDeclarations)
{
// Reverse the list to get the parent classes in the correct order
parentClassDeclarations.Reverse();

// Generate the parent class declarations
var parentClassDeclarationsString = string.Join("\n{\n", parentClassDeclarations);
if (!string.IsNullOrWhiteSpace(parentClassDeclarationsString))
{
parentClassDeclarationsString += "\n{\n";
}

return parentClassDeclarationsString;
}

public static string GenerateClosingBrackets(int numberOfBrackets)
{
var closingBrackets = new string('}', numberOfBrackets);
closingBrackets = closingBrackets.Replace("}", "}\n");
if (!string.IsNullOrWhiteSpace(closingBrackets))
{
closingBrackets = "\n" + closingBrackets;
}

return closingBrackets;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,7 @@ public partial class IViewForGenerator
token.ThrowIfCancellationRequested();

return new(
targetInfo.FileHintName,
targetInfo.TargetName,
targetInfo.TargetNamespace,
targetInfo.TargetNamespaceWithNamespace,
targetInfo.TargetVisibility,
targetInfo.TargetType,
targetInfo,
viewModelTypeName!,
viewForBaseType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Initialize(IncrementalGeneratorInitializationContext context)
context.RegisterSourceOutput(iViewForInfo, static (context, input) =>
{
var groupedPropertyInfo = input.GroupBy(
static info => (info.FileHintName, info.TargetName, info.TargetNamespace, info.TargetVisibility, info.TargetType),
static info => (info.TargetInfo.FileHintName, info.TargetInfo.TargetName, info.TargetInfo.TargetNamespace, info.TargetInfo.TargetVisibility, info.TargetInfo.TargetType),
static info => info)
.ToImmutableArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,14 @@
// See the LICENSE file in the project root for full license information.

using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Models;

namespace ReactiveUI.SourceGenerators.Input.Models;

/// <summary>
/// A model with gathered info on a given command method.
/// </summary>
internal sealed record IViewForInfo(
string FileHintName,
string TargetName,
string TargetNamespace,
string TargetNamespaceWithNamespace,
string TargetVisibility,
string TargetType,
TargetInfo TargetInfo,
string ViewModelTypeName,
IViewForBaseType BaseType);
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
// See the LICENSE file in the project root for full license information.

using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Models;

namespace ReactiveUI.SourceGenerators.Reactive.Models;

/// <summary>
/// A model with gathered info on a given field.
/// </summary>
internal sealed record ObservableFieldInfo(
string FileHintName,
string TargetName,
string TargetNamespace,
string TargetNamespaceWithNamespace,
string TargetVisibility,
string TargetType,
TargetInfo TargetInfo,
string TypeNameWithNullabilityAnnotations,
string FieldName,
string PropertyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@

using System.Globalization;
using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Models;

namespace ReactiveUI.SourceGenerators.ObservableAsProperty.Models
{
internal record ObservableMethodInfo(
string FileHintName,
string TargetName,
string TargetNamespace,
string TargetNamespaceWithNamespace,
string TargetVisibility,
string TargetType,
string MethodName,
string MethodReturnType,
string? ArgumentType,
string PropertyName,
string ObservableType,
bool IsNullableType,
bool IsProperty,
EquatableArray<string> ForwardedPropertyAttributes)
TargetInfo TargetInfo,
string MethodName,
string MethodReturnType,
string? ArgumentType,
string PropertyName,
string ObservableType,
bool IsNullableType,
bool IsProperty,
EquatableArray<string> ForwardedPropertyAttributes)
{
public string GetGeneratedFieldName()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,7 @@ public sealed partial class ObservableAsPropertyGenerator

return new(
new(
targetInfo.FileHintName,
targetInfo.TargetName,
targetInfo.TargetNamespace,
targetInfo.TargetNamespaceWithNamespace,
targetInfo.TargetVisibility,
targetInfo.TargetType,
targetInfo,
typeNameWithNullabilityAnnotations,
fieldName,
propertyName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private static void RunObservableAsPropertyFromField(in IncrementalGeneratorInit
var groupedPropertyInfo = input
.Where(static x => x.Value != null)
.Select(static x => x.Value!).GroupBy(
static info => (info.FileHintName, info.TargetName, info.TargetNamespace, info.TargetVisibility, info.TargetType),
static info => (info.TargetInfo.FileHintName, info.TargetInfo.TargetName, info.TargetInfo.TargetNamespace, info.TargetInfo.TargetVisibility, info.TargetInfo.TargetType),
static info => info)
.ToImmutableArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,7 @@ public sealed partial class ObservableAsPropertyGenerator

return new(
new(
targetInfo.FileHintName,
targetInfo.TargetName,
targetInfo.TargetNamespace,
targetInfo.TargetNamespaceWithNamespace,
targetInfo.TargetVisibility,
targetInfo.TargetType,
targetInfo,
methodSymbol.Name,
methodSymbol.ReturnType.GetFullyQualifiedNameWithNullabilityAnnotations(),
methodSymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
Expand Down Expand Up @@ -120,12 +115,7 @@ public sealed partial class ObservableAsPropertyGenerator

return new(
new(
targetInfo.FileHintName,
targetInfo.TargetName,
targetInfo.TargetNamespace,
targetInfo.TargetNamespaceWithNamespace,
targetInfo.TargetVisibility,
targetInfo.TargetType,
targetInfo,
propertySymbol.Name,
propertySymbol.Type.GetFullyQualifiedNameWithNullabilityAnnotations(),
propertySymbol.Parameters.FirstOrDefault()?.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private static void RunObservableAsPropertyFromObservable(in IncrementalGenerato
var groupedPropertyInfo = input
.Where(static x => x.Value != null)
.Select(static x => x.Value!).GroupBy(
static info => (info.FileHintName, info.TargetName, info.TargetNamespace, info.TargetVisibility, info.TargetType),
static info => (info.TargetInfo.FileHintName, info.TargetInfo.TargetName, info.TargetInfo.TargetNamespace, info.TargetInfo.TargetVisibility, info.TargetInfo.TargetType),
static info => info)
.ToImmutableArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@
// See the LICENSE file in the project root for full license information.

using ReactiveUI.SourceGenerators.Helpers;
using ReactiveUI.SourceGenerators.Models;

namespace ReactiveUI.SourceGenerators.Reactive.Models;

/// <summary>
/// A model with gathered info on a given field.
/// </summary>
internal sealed record PropertyInfo(
string FileHintName,
string TargetName,
string TargetNamespace,
string TargetNamespaceWithNamespace,
string TargetVisibility,
string TargetType,
TargetInfo TargetInfo,
string TypeNameWithNullabilityAnnotations,
string FieldName,
string PropertyName,
Expand Down
Loading