Skip to content

Commit

Permalink
feat: ListNode<T>.WithNode overrides cov-returns
Browse files Browse the repository at this point in the history
closes #73
  • Loading branch information
amis92 committed Feb 14, 2021
1 parent 352e3d6 commit 4deee57
Showing 1 changed file with 9 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,33 +187,21 @@ private MemberDeclarationSyntax AcceptGenericMethod()

private MemberDeclarationSyntax CreateWithNodesMethod()
{
const string NodesVarName = "nodes";
var nodes = IdentifierName("nodes");
var nodeList = Descriptor.GetNodeTypeIdentifierName().ToNodeListType();
var listNode = IdentifierName(Descriptor.GetListNodeTypeName());
return
MethodDeclaration(
GenericName(Names.ListNode)
.AddTypeArgumentListArguments(
Descriptor.GetNodeTypeIdentifierName()),
Names.WithNodes)
.AddModifiers(
SyntaxKind.PublicKeyword,
SyntaxKind.OverrideKeyword)
MethodDeclaration(listNode, Names.WithNodes)
.AddModifiers(SyntaxKind.PublicKeyword, SyntaxKind.OverrideKeyword)
.AddParameterListParameters(
Parameter(
Identifier(NodesVarName))
.WithType(
Descriptor.GetNodeTypeIdentifierName().ToNodeListType()))
Parameter(nodes.Identifier)
.WithType(nodeList))
.AddBodyStatements(
ReturnStatement(
ConditionalExpression(
BinaryExpression(
SyntaxKind.EqualsExpression,
ThisExpression().Dot(IdentifierName(Names.NodeList)),
IdentifierName(NodesVarName)),
ThisExpression().Dot(IdentifierName(Names.NodeList)).OpEquals(nodes),
ThisExpression(),
IdentifierName(NodesVarName)
.Dot(
IdentifierName(Names.ToListNode))
.Invoke())));
nodes.Dot(IdentifierName(Names.ToListNode)).Invoke())));
}
}
}

0 comments on commit 4deee57

Please sign in to comment.