Skip to content

Commit f3daf90

Browse files
author
Joanna May
committed
refactor: rename to type node
1 parent 71c82c5 commit f3daf90

File tree

6 files changed

+31
-29
lines changed

6 files changed

+31
-29
lines changed

Chickensoft.Introspection.Generator.Tests/test/src/models/DeclaredPropertyTest.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ public void Equality() {
1616
IsRequired: false,
1717
IsNullable: false,
1818
DefaultValueExpression: null,
19-
GenericType: new GenericTypeNode(
20-
"System.String", false, Children: ImmutableArray<GenericTypeNode>.Empty
19+
TypeNode: new TypeNode(
20+
"System.String", false, Children: ImmutableArray<TypeNode>.Empty
2121
),
2222
Attributes: ImmutableArray<DeclaredAttribute>.Empty
2323
);
@@ -35,8 +35,8 @@ public void Equality() {
3535
IsRequired: false,
3636
IsNullable: false,
3737
DefaultValueExpression: null,
38-
GenericType: new GenericTypeNode(
39-
"System.String", false, Children: ImmutableArray<GenericTypeNode>.Empty
38+
TypeNode: new TypeNode(
39+
"System.String", false, Children: ImmutableArray<TypeNode>.Empty
4040
),
4141
Attributes: ImmutableArray<DeclaredAttribute>.Empty
4242
)
@@ -50,8 +50,8 @@ public void Equality() {
5050
IsRequired: false,
5151
IsNullable: false,
5252
DefaultValueExpression: null,
53-
GenericType: new GenericTypeNode(
54-
"System.String", false, Children: ImmutableArray<GenericTypeNode>.Empty
53+
TypeNode: new TypeNode(
54+
"System.String", false, Children: ImmutableArray<TypeNode>.Empty
5555
),
5656
Attributes: new DeclaredAttribute[] {
5757
new("", ImmutableArray<string>.Empty, ImmutableArray<string>.Empty)
@@ -65,8 +65,8 @@ public void Equality() {
6565
IsRequired: false,
6666
IsNullable: false,
6767
DefaultValueExpression: null,
68-
GenericType: new GenericTypeNode(
69-
"System.String", false, Children: ImmutableArray<GenericTypeNode>.Empty
68+
TypeNode: new TypeNode(
69+
"System.String", false, Children: ImmutableArray<TypeNode>.Empty
7070
),
7171
Attributes: ImmutableArray<DeclaredAttribute>.Empty
7272
)

Chickensoft.Introspection.Generator.Tests/test/src/models/GenericTypeNodeTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ namespace Chickensoft.Introspection.Generator.Tests.Models;
55
using Shouldly;
66
using Xunit;
77

8-
public class GenericTypeNodeTest {
8+
public class TypeNodeTest {
99
[Fact]
1010
public void Equality() {
11-
var node = new GenericTypeNode(
12-
"Type", false, ImmutableArray<GenericTypeNode>.Empty
11+
var node = new TypeNode(
12+
"Type", false, ImmutableArray<TypeNode>.Empty
1313
);
1414

1515
node.Equals(null).ShouldBeFalse();

Chickensoft.Introspection.Generator/src/TypeGenerator.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ TypeDeclarationSyntax type
539539
var defaultValueExpression =
540540
property.Initializer?.Value.NormalizeWhitespace().ToString();
541541

542-
var genericType = GenericTypeNode.Create(propType, isNullable);
542+
var genericType = TypeNode.Create(propType, isNullable);
543543

544544
properties.Add(
545545
new DeclaredProperty(
@@ -550,7 +550,7 @@ TypeDeclarationSyntax type
550550
IsRequired: isRequired,
551551
IsNullable: isNullable,
552552
DefaultValueExpression: defaultValueExpression,
553-
GenericType: genericType,
553+
TypeNode: genericType,
554554
Attributes: propertyAttributes
555555
)
556556
);

Chickensoft.Introspection.Generator/src/models/DeclaredProperty.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace Chickensoft.Introspection.Generator.Models;
1414
/// <param name="IsNullable">True if the property is nullable.</param>
1515
/// <param name="DefaultValueExpression">Expression to use as the default
1616
/// value.</param>
17-
/// <param name="GenericType">Type of the </param>
17+
/// <param name="TypeNode">Type of the </param>
1818
/// <param name="Attributes">Attributes applied to the </param>
1919
public sealed record DeclaredProperty(
2020
string Name,
@@ -24,7 +24,7 @@ public sealed record DeclaredProperty(
2424
bool IsRequired,
2525
bool IsNullable,
2626
string? DefaultValueExpression,
27-
GenericTypeNode GenericType,
27+
TypeNode TypeNode,
2828
ImmutableArray<DeclaredAttribute> Attributes
2929
) {
3030
public void Write(IndentedTextWriter writer, string typeSimpleNameClosed) {
@@ -37,7 +37,7 @@ public void Write(IndentedTextWriter writer, string typeSimpleNameClosed) {
3737
? $"static (object obj) => (({typeSimpleNameClosed})obj).{Name}"
3838
: "null";
3939

40-
var type = GenericType.ClosedType;
40+
var type = TypeNode.ClosedType;
4141

4242
var setter = HasSetter
4343
? (
@@ -58,7 +58,7 @@ public void Write(IndentedTextWriter writer, string typeSimpleNameClosed) {
5858
writer.WriteLine($"Getter: {getter},");
5959
writer.WriteLine($"Setter: {setter},");
6060
writer.Write("GenericType: ");
61-
GenericType.Write(writer);
61+
TypeNode.Write(writer);
6262
writer.WriteLine(",");
6363
writer.WriteLine(
6464
"Attributes: new System.Collections.Generic.Dictionary" +
@@ -83,7 +83,7 @@ other is not null &&
8383
IsRequired == other.IsRequired &&
8484
IsNullable == other.IsNullable &&
8585
DefaultValueExpression == other.DefaultValueExpression &&
86-
GenericType.Equals(other.GenericType) &&
86+
TypeNode.Equals(other.TypeNode) &&
8787
Attributes.SequenceEqual(other.Attributes);
8888

8989
public override int GetHashCode() => HashCode.Combine(
@@ -94,7 +94,7 @@ public override int GetHashCode() => HashCode.Combine(
9494
IsRequired,
9595
IsNullable,
9696
DefaultValueExpression,
97-
GenericType,
97+
TypeNode,
9898
Attributes
9999
);
100100
}

Chickensoft.Introspection.Generator/src/models/DeclaredType.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -558,14 +558,14 @@ IEnumerable<DeclaredType> baseTypes
558558
.Where(prop => prop.IsInit || prop.IsRequired)
559559
.Select(
560560
(prop) => {
561-
var bang = prop.GenericType.IsNullable ? "" : "!";
561+
var bang = prop.TypeNode.IsNullable ? "" : "!";
562562
return
563563
$"{prop.Name} = args.ContainsKey(\"{prop.Name}\") " +
564-
$"? ({prop.GenericType.ClosedType})args[\"{prop.Name}\"] : " +
564+
$"? ({prop.TypeNode.ClosedType})args[\"{prop.Name}\"] : " +
565565
$"{(
566566
prop.DefaultValueExpression is { } value
567567
? value
568-
: $"default({prop.GenericType.ClosedType}){bang}"
568+
: $"default({prop.TypeNode.ClosedType}){bang}"
569569
)}";
570570
}
571571
);

Chickensoft.Introspection.Generator/src/models/GenericTypeNode.cs renamed to Chickensoft.Introspection.Generator/src/models/TypeNode.cs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ namespace Chickensoft.Introspection.Generator.Models;
1313
// Not to be confused with the type resolution tree node, which has to do with
1414
// where types are. This represents a generic type as a hierarchy of all the
1515
// types that comprise it.
16-
public sealed record GenericTypeNode(
16+
public sealed record TypeNode(
1717
string Type,
1818
bool IsNullable,
19-
ImmutableArray<GenericTypeNode> Children
19+
ImmutableArray<TypeNode> Children
2020
) {
2121
/// <summary>
2222
/// Name of the type, including any generic type arguments — i.e., the closed
@@ -36,17 +36,17 @@ ImmutableArray<GenericTypeNode> Children
3636
/// </summary>
3737
/// <param name="typeSyntax">Generic name syntax.</param>
3838
/// <returns>Generic type node tree.</returns>
39-
public static GenericTypeNode Create(
39+
public static TypeNode Create(
4040
TypeSyntax typeSyntax, bool isNullable
4141
) {
4242
isNullable = isNullable || typeSyntax.IsNullable();
4343
typeSyntax = typeSyntax.UnwrapNullable();
4444

4545
if (typeSyntax is not GenericNameSyntax genericNameSyntax) {
46-
return new GenericTypeNode(
46+
return new TypeNode(
4747
typeSyntax.NormalizeWhitespace().ToString(),
4848
IsNullable: isNullable,
49-
Children: ImmutableArray<GenericTypeNode>.Empty
49+
Children: ImmutableArray<TypeNode>.Empty
5050
);
5151
}
5252

@@ -61,7 +61,7 @@ public static GenericTypeNode Create(
6161
})
6262
.ToImmutableArray();
6363

64-
return new GenericTypeNode(type, isNullable, children);
64+
return new TypeNode(type, isNullable, children);
6565
}
6666

6767
public void Write(IndentedTextWriter writer) {
@@ -105,13 +105,15 @@ public void Write(IndentedTextWriter writer) {
105105
writer.Write(")");
106106
}
107107

108-
public bool Equals(GenericTypeNode? other) =>
108+
public bool Equals(TypeNode? other) =>
109109
other is not null &&
110110
Type == other.Type &&
111+
IsNullable == other.IsNullable &&
111112
Children.SequenceEqual(other.Children);
112113

113114
public override int GetHashCode() => HashCode.Combine(
114115
Type,
116+
IsNullable,
115117
Children
116118
);
117119
}

0 commit comments

Comments
 (0)