code: public static void createWithDepth(Program program, TreeNode x, int allowableDepth, TGPInitializationStrategy method, RandEngine randEngine) {
  
        int child_count = x.arity();
  
        for (int i = 0; i != child_count; ++i)
        {
           Primitive primitive = anyPrimitive(program, allowableDepth, method, randEngine);
           TreeNode child = new TreeNode(primitive);
           x.getChildren().add(child);
  
           if (!primitive.isTerminal())
           {
              createWithDepth(program, child, allowableDepth - 1, method, randEngine);
           }
        }
     }
docs: / <param name="method">The method used to build the subtree</param>