Skip to content

Commit 8e3032b

Browse files
committed
HqlSqlWalker.cs: Remove use of the ASTNode.NextSibling setter, since its name doesn't give clear indication of semantics. And in practice it was the wrong semantics for the current users. See NH-3624.
1 parent 754629c commit 8e3032b

File tree

3 files changed

+25
-28
lines changed

3 files changed

+25
-28
lines changed

src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -229,9 +229,7 @@ void PrepareVersioned(IASTNode updateNode, IASTNode versioned)
229229
EvaluateAssignment(eq, persister, 0);
230230

231231
IASTNode setClause = updateStatement.SetClause;
232-
IASTNode currentFirstSetElement = setClause.GetFirstChild();
233-
setClause.SetFirstChild(eq);
234-
eq.NextSibling= currentFirstSetElement;
232+
setClause.InsertChild(0, eq);
235233
}
236234
}
237235

@@ -296,9 +294,7 @@ void PostProcessInsert(IASTNode insert)
296294

297295
if (idSelectExprNode != null)
298296
{
299-
IASTNode currentFirstSelectExprNode = selectClause.GetFirstChild();
300-
selectClause.SetFirstChild(idSelectExprNode);
301-
idSelectExprNode.NextSibling= currentFirstSelectExprNode;
297+
selectClause.InsertChild(0, idSelectExprNode);
302298

303299
insertStatement.IntoClause.PrependIdColumnSpec();
304300
}
@@ -343,9 +339,7 @@ void PostProcessInsert(IASTNode insert)
343339
}
344340
}
345341

346-
IASTNode currentFirstSelectExprNode = selectClause.GetFirstChild();
347-
selectClause.SetFirstChild(versionValueNode);
348-
versionValueNode.NextSibling = currentFirstSelectExprNode;
342+
selectClause.InsertChild(0, versionValueNode);
349343

350344
insertStatement.IntoClause.PrependVersionColumnSpec();
351345
}

src/NHibernate/Hql/Ast/ANTLR/Tree/ASTNode.cs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -260,24 +260,27 @@ public IASTNode NextSibling
260260

261261
return null;
262262
}
263-
set
264-
{
265-
if (_parent != null)
266-
{
267-
if (_parent.ChildCount > (ChildIndex + 1))
268-
{
269-
_parent.SetChild(ChildIndex + 1, value);
270-
}
271-
else
272-
{
273-
AddSibling(value);
274-
}
275-
}
276-
else
277-
{
278-
throw new InvalidOperationException("Trying set NextSibling without a parent.");
279-
}
280-
}
263+
// Setter commented out 2014-07-26. I don't like it since it drops the current next sibling from
264+
// the tree, and the name of the property doesn't give a clear indication if it overwrites or not.
265+
// Better to use InsertChild() on the parent.
266+
//set
267+
//{
268+
// if (_parent != null)
269+
// {
270+
// if (_parent.ChildCount > (ChildIndex + 1))
271+
// {
272+
// _parent.SetChild(ChildIndex + 1, value);
273+
// }
274+
// else
275+
// {
276+
// AddSibling(value);
277+
// }
278+
// }
279+
// else
280+
// {
281+
// throw new InvalidOperationException("Trying set NextSibling without a parent.");
282+
// }
283+
//}
281284
}
282285

283286
public IASTNode GetChild(int index)

src/NHibernate/Hql/Ast/ANTLR/Tree/IASTNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public interface IASTNode : IEnumerable<IASTNode>
1515
int ChildCount { get; }
1616
int ChildIndex { get; }
1717
IASTNode Parent { get; set; }
18-
IASTNode NextSibling { get; set; }
18+
IASTNode NextSibling { get; /*set;*/ }
1919
IASTNode GetChild(int index);
2020
IASTNode GetFirstChild();
2121
void SetFirstChild(IASTNode newChild);

0 commit comments

Comments
 (0)