Skip to content

Commit b5f7958

Browse files
authored
Merge pull request #105 from AArnott/fix104
Fully-qualify type references to IRecursiveParentWithOrderedChildren
2 parents 53caec2 + 82e8943 commit b5f7958

File tree

4 files changed

+73
-37
lines changed

4 files changed

+73
-37
lines changed
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
namespace ImmutableObjectGraph.Generation.Tests.TestSources
1+
namespace TestSources // Don't use ImmutableObjectGraph namespace so that we're testing that we fully qualify type names.
22
{
3-
using System.Collections.Immutable;
4-
5-
[GenerateImmutable]
3+
[ImmutableObjectGraph.Generation.GenerateImmutable]
64
partial class Node
75
{
8-
readonly ImmutableArray<Node> children;
6+
readonly System.Collections.Immutable.ImmutableArray<Node> children;
97
}
108
}

src/ImmutableObjectGraph.Generation/CodeGen+DeepMutationGen.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,20 @@ private MethodDeclarationSyntax CreateRemoveDescendentMethod()
183183
.AddVariables(SyntaxFactory.VariableDeclarator(newSpineVar.Identifier).WithInitializer(SyntaxFactory.EqualsValueClause(
184184
SyntaxFactory.InvocationExpression(Syntax.CreateImmutableStack(this.applyTo.RecursiveType.TypeSyntax))
185185
.AddArgumentListArguments(SyntaxFactory.Argument(newParentVar)))))),
186-
// return (TRecursiveParent)this.ReplaceDescendent(spine, newSpine, spineIncludesDeletedElement: true).Peek();
186+
// return (TRecursiveParent)ImmutableObjectGraph.RecursiveTypeExtensions.ReplaceDescendent(this, spine, newSpine, spineIncludesDeletedElement: true).Peek();
187187
SyntaxFactory.ReturnStatement(
188188
SyntaxFactory.CastExpression(
189189
this.applyTo.RecursiveParent.TypeSyntax,
190190
SyntaxFactory.InvocationExpression(
191191
SyntaxFactory.MemberAccessExpression(
192192
SyntaxKind.SimpleMemberAccessExpression,
193-
SyntaxFactory.InvocationExpression(Syntax.ThisDot(ReplaceDescendentMethodName))
193+
SyntaxFactory.InvocationExpression(
194+
SyntaxFactory.MemberAccessExpression(
195+
SyntaxKind.SimpleMemberAccessExpression,
196+
Syntax.GetTypeSyntax(typeof(RecursiveTypeExtensions)),
197+
ReplaceDescendentMethodName))
194198
.AddArgumentListArguments(
199+
SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
195200
SyntaxFactory.Argument(spineVar),
196201
SyntaxFactory.Argument(newSpineVar),
197202
SyntaxFactory.Argument(SyntaxFactory.NameColon("spineIncludesDeletedElement"), NoneToken, SyntaxFactory.LiteralExpression(SyntaxKind.TrueLiteralExpression))
@@ -229,15 +234,20 @@ private MethodDeclarationSyntax CreateReplaceDescendentSameIdentityMethod()
229234
SyntaxFactory.ThrowStatement(
230235
SyntaxFactory.ObjectCreationExpression(Syntax.GetTypeSyntax(typeof(ArgumentException))).AddArgumentListArguments(
231236
SyntaxFactory.Argument(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal("Old value not found."))))))),
232-
// return (TemplateType)this.ReplaceDescendent(spine, ImmutableStack.Create(updatedNode), spineIncludesDeletedElement: false).Peek();
237+
// return (TemplateType)ImmutableObjectGraph.RecursiveTypeExtensions.ReplaceDescendent(this, spine, ImmutableStack.Create(updatedNode), spineIncludesDeletedElement: false).Peek();
233238
SyntaxFactory.ReturnStatement(
234239
SyntaxFactory.CastExpression(
235240
this.applyTo.TypeSyntax,
236241
SyntaxFactory.InvocationExpression(
237242
SyntaxFactory.MemberAccessExpression(
238243
SyntaxKind.SimpleMemberAccessExpression,
239-
SyntaxFactory.InvocationExpression(Syntax.ThisDot(ReplaceDescendentMethodName))
244+
SyntaxFactory.InvocationExpression(
245+
SyntaxFactory.MemberAccessExpression(
246+
SyntaxKind.SimpleMemberAccessExpression,
247+
Syntax.GetTypeSyntax(typeof(RecursiveTypeExtensions)),
248+
ReplaceDescendentMethodName))
240249
.AddArgumentListArguments(
250+
SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
241251
SyntaxFactory.Argument(spineVar),
242252
SyntaxFactory.Argument(SyntaxFactory.InvocationExpression(Syntax.CreateImmutableStack()).AddArgumentListArguments(
243253
SyntaxFactory.Argument(updatedNodeParameter))),
@@ -278,15 +288,20 @@ private MethodDeclarationSyntax CreateReplaceDescendentDifferentIdentityMethod()
278288
SyntaxFactory.ThrowStatement(
279289
SyntaxFactory.ObjectCreationExpression(Syntax.GetTypeSyntax(typeof(ArgumentException))).AddArgumentListArguments(
280290
SyntaxFactory.Argument(SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal("Old value not found."))))))),
281-
// return (TemplateType)this.ReplaceDescendent(spine, ImmutableStack.Create(replacement), spineIncludesDeletedElement: false).Peek();
291+
// return (TemplateType)ImmutableObjectGraph.RecursiveTypeExtensions.ReplaceDescendent(this, spine, ImmutableStack.Create(replacement), spineIncludesDeletedElement: false).Peek();
282292
SyntaxFactory.ReturnStatement(
283293
SyntaxFactory.CastExpression(
284294
this.applyTo.TypeSyntax,
285295
SyntaxFactory.InvocationExpression(
286296
SyntaxFactory.MemberAccessExpression(
287297
SyntaxKind.SimpleMemberAccessExpression,
288-
SyntaxFactory.InvocationExpression(Syntax.ThisDot(ReplaceDescendentMethodName))
298+
SyntaxFactory.InvocationExpression(
299+
SyntaxFactory.MemberAccessExpression(
300+
SyntaxKind.SimpleMemberAccessExpression,
301+
Syntax.GetTypeSyntax(typeof(RecursiveTypeExtensions)),
302+
ReplaceDescendentMethodName))
289303
.AddArgumentListArguments(
304+
SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
290305
SyntaxFactory.Argument(spineVar),
291306
SyntaxFactory.Argument(SyntaxFactory.InvocationExpression(Syntax.CreateImmutableStack()).AddArgumentListArguments(
292307
SyntaxFactory.Argument(replacementParameter))),

src/ImmutableObjectGraph.Generation/CodeGen+EnumerableRecursiveParentGen.cs

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ private MethodDeclarationSyntax CreateGetParentMethod()
6262
.AddAttributeLists(PureAttributeList)
6363
.AddParameterListParameters(SyntaxFactory.Parameter(descendentParam.Identifier).WithType(this.applyTo.RecursiveType.TypeSyntax))
6464
.WithBody(SyntaxFactory.Block(
65-
// return this.GetParent<TRecursiveParent, TRecursiveType>(descendent);
65+
// return ImmutableObjectGraph.RecursiveTypeExtensions.GetParent<TRecursiveParent, TRecursiveType>(this, descendent);
6666
SyntaxFactory.ReturnStatement(
6767
SyntaxFactory.InvocationExpression(
68-
Syntax.ThisDot(
68+
SyntaxFactory.MemberAccessExpression(
69+
SyntaxKind.SimpleMemberAccessExpression,
70+
Syntax.GetTypeSyntax(typeof(RecursiveTypeExtensions)),
6971
SyntaxFactory.GenericName(nameof(RecursiveTypeExtensions.GetParent))
7072
.AddTypeArgumentListArguments(this.applyTo.RecursiveParent.TypeSyntax, this.applyTo.RecursiveType.TypeSyntax)))
71-
.AddArgumentListArguments(SyntaxFactory.Argument(descendentParam)))));
73+
.AddArgumentListArguments(
74+
SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
75+
SyntaxFactory.Argument(descendentParam)))));
7276
}
7377

7478
private void ImplementIEnumerableInterfaces()
@@ -129,25 +133,32 @@ private void ImplementRecursiveParentInterface()
129133
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
130134
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(DebuggerBrowsableNeverAttribute))));
131135

132-
// public ParentedRecursiveType<TRecursiveParent, TRecursiveType> GetParentedNode(uint identity)
136+
// public ImmutableObjectGraph.ParentedRecursiveType<TRecursiveParent, TRecursiveType> GetParentedNode(uint identity)
133137
this.innerMembers.Add(
134138
SyntaxFactory.MethodDeclaration(
135-
SyntaxFactory.GenericName(nameof(ParentedRecursiveType<IRecursiveParent<IRecursiveType>, IRecursiveType>)).AddTypeArgumentListArguments(
136-
this.applyTo.RecursiveParent.TypeSyntax,
137-
this.applyTo.RecursiveType.TypeSyntax),
139+
SyntaxFactory.QualifiedName(
140+
SyntaxFactory.IdentifierName(nameof(ImmutableObjectGraph)),
141+
SyntaxFactory.GenericName(nameof(ParentedRecursiveType<IRecursiveParent<IRecursiveType>, IRecursiveType>)).AddTypeArgumentListArguments(
142+
this.applyTo.RecursiveParent.TypeSyntax,
143+
this.applyTo.RecursiveType.TypeSyntax)),
138144
nameof(IRecursiveParent.GetParentedNode))
139145
.AddModifiers(SyntaxFactory.Token(SyntaxKind.PublicKeyword))
140146
.AddAttributeLists(PureAttributeList)
141147
//.WithExplicitInterfaceSpecifier(SyntaxFactory.ExplicitInterfaceSpecifier(Syntax.GetTypeSyntax(typeof(IRecursiveParent))))
142148
.AddParameterListParameters(RequiredIdentityParameter)
143149
.WithBody(SyntaxFactory.Block(
144-
// return this.GetParentedNode<TRecursiveParent, TRecursiveType>(identity);
150+
// return ImmutableObjectGraph.RecursiveTypeExtensions.GetParentedNode<TRecursiveParent, TRecursiveType>(this, identity);
145151
SyntaxFactory.ReturnStatement(
146152
SyntaxFactory.InvocationExpression(
147-
Syntax.ThisDot(SyntaxFactory.GenericName(nameof(RecursiveTypeExtensions.GetParentedNode)).AddTypeArgumentListArguments(
148-
this.applyTo.RecursiveParent.TypeSyntax,
149-
this.applyTo.RecursiveType.TypeSyntax)))
150-
.AddArgumentListArguments(SyntaxFactory.Argument(IdentityParameterName))))));
153+
SyntaxFactory.MemberAccessExpression(
154+
SyntaxKind.SimpleMemberAccessExpression,
155+
Syntax.GetTypeSyntax(typeof(RecursiveTypeExtensions)),
156+
SyntaxFactory.GenericName(nameof(RecursiveTypeExtensions.GetParentedNode)).AddTypeArgumentListArguments(
157+
this.applyTo.RecursiveParent.TypeSyntax,
158+
this.applyTo.RecursiveType.TypeSyntax)))
159+
.AddArgumentListArguments(
160+
SyntaxFactory.Argument(SyntaxFactory.ThisExpression()),
161+
SyntaxFactory.Argument(IdentityParameterName))))));
151162

152163
// ParentedRecursiveType<IRecursiveParent<IRecursiveType>, IRecursiveType> IRecursiveParent.GetParentedNode(<#= templateType.RequiredIdentityField.TypeName #> identity) {
153164
var parentedVar = SyntaxFactory.IdentifierName("parented");
@@ -194,7 +205,7 @@ private void ImplementOrderedChildrenInterface()
194205
this.innerMembers.Add(SyntaxFactory.PropertyDeclaration(
195206
Syntax.IReadOnlyListOf(Syntax.GetTypeSyntax(typeof(IRecursiveType))),
196207
nameof(IRecursiveParentWithOrderedChildren.Children))
197-
.WithExplicitInterfaceSpecifier(SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.IdentifierName(nameof(IRecursiveParentWithOrderedChildren))))
208+
.WithExplicitInterfaceSpecifier(SyntaxFactory.ExplicitInterfaceSpecifier(Syntax.GetTypeSyntax(typeof(IRecursiveParentWithOrderedChildren))))
198209
.WithExpressionBody(SyntaxFactory.ArrowExpressionClause(Syntax.ThisDot(SyntaxFactory.IdentifierName(this.generator.applyToMetaType.RecursiveField.Name))))
199210
.WithSemicolonToken(SyntaxFactory.Token(SyntaxKind.SemicolonToken))
200211
.AddAttributeLists(SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(DebuggerBrowsableNeverAttribute))));
@@ -204,7 +215,7 @@ private void ImplementOrderedChildrenInterface()
204215
this.innerMembers.Add(SyntaxFactory.MethodDeclaration(
205216
SyntaxFactory.PredefinedType(SyntaxFactory.Token(SyntaxKind.IntKeyword)),
206217
nameof(IRecursiveParentWithOrderedChildren.IndexOf))
207-
.WithExplicitInterfaceSpecifier(SyntaxFactory.ExplicitInterfaceSpecifier(SyntaxFactory.IdentifierName(nameof(IRecursiveParentWithOrderedChildren))))
218+
.WithExplicitInterfaceSpecifier(SyntaxFactory.ExplicitInterfaceSpecifier(Syntax.GetTypeSyntax(typeof(IRecursiveParentWithOrderedChildren))))
208219
.AddParameterListParameters(SyntaxFactory.Parameter(valueParameterName.Identifier).WithType(Syntax.GetTypeSyntax(typeof(IRecursiveType))))
209220
.WithBody(SyntaxFactory.Block(
210221
// return this.Children.IndexOf((<#= templateType.RecursiveType.TypeName #>)value);

0 commit comments

Comments
 (0)