File tree Expand file tree Collapse file tree
main/java/com/puppycrawl/tools/checkstyle
test/java/com/puppycrawl/tools/checkstyle Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -374,6 +374,11 @@ public DetailAstImpl getFirstChild() {
374374 return (DetailAstImpl ) super .getFirstChild ();
375375 }
376376
377+ @ Override
378+ public boolean hasChildren () {
379+ return getFirstChild () != null ;
380+ }
381+
377382 /**
378383 * Clears the child count for the ast instance.
379384 * @param ast The ast to clear.
Original file line number Diff line number Diff line change @@ -118,4 +118,10 @@ public interface DetailAST {
118118 */
119119 int getNumberOfChildren ();
120120
121+ /**
122+ * Returns whether this AST has any children.
123+ *
124+ * @return {@code true} if this AST has any children.
125+ */
126+ boolean hasChildren ();
121127}
Original file line number Diff line number Diff line change 1919
2020package com .puppycrawl .tools .checkstyle ;
2121
22+ import static com .google .common .truth .Truth .assertWithMessage ;
2223import static org .junit .jupiter .api .Assertions .assertEquals ;
2324import static org .junit .jupiter .api .Assertions .assertFalse ;
2425import static org .junit .jupiter .api .Assertions .assertNotNull ;
@@ -134,6 +135,22 @@ public void testGetChildCount() throws Exception {
134135 assertEquals (firstLevelA , firstLevelB .getPreviousSibling (), "Invalid previous sibling" );
135136 }
136137
138+ @ Test
139+ public void testHasChildren () throws Exception {
140+ final DetailAstImpl root = new DetailAstImpl ();
141+ final DetailAstImpl child = new DetailAstImpl ();
142+
143+ root .setFirstChild (child );
144+ getSetParentMethod ().invoke (child , root );
145+
146+ assertWithMessage ("Root node should have children" )
147+ .that (root .hasChildren ())
148+ .isTrue ();
149+ assertWithMessage ("Child node should have no children" )
150+ .that (child .hasChildren ())
151+ .isFalse ();
152+ }
153+
137154 @ Test
138155 public void testGetChildCountType () throws Exception {
139156 final DetailAstImpl root = new DetailAstImpl ();
You can’t perform that action at this time.
0 commit comments