<commit_before>require 'java'
require 'jrubyfx'

class ASTTreeItem < Java::javafx.scene.control.TreeItem
  include JRubyFX
  
  attr_reader :node
  
  def initialize(node)
    @node = node
    super(node_string)
  end
  
  def node_string
    node_information = @node.respond_to?(:name) ? ":#{@node.name}" : ""
    "#{@node.node_name}#{node_information} #{@node.position.start_line}"    
  end
  
end

class ASTTreeViewBuilder
  include JRubyFX
  attr_accessor :tree_view
  
  def initialize(tree_view)
    @tree_view = tree_view
  end
  
  def build_tree_item(node)
    ASTTreeItem.new(node)
  end

  def build_view(root)
    @tree_view.root = build_tree_item(root)
    root.child_nodes.each { |child| build_view_inner(child, @tree_view.root) }
  end
  
  def build_view_inner(node, parent_item)
    tree_item = build_tree_item(node)
    parent_item.children << tree_item
    node.child_nodes.each { |child| build_view_inner(child, tree_item) }
  end
  private :build_view_inner
end

if __FILE__ == $0
  require 'jruby'
  root = JRuby.parse("def foo; 42; end; foo")
  builder = ASTTreeViewBuilder.new(nil)
  builder.build_view(root)
end
<commit_msg>default to expand each ASTTreeItem<commit_after>require 'java'
require 'jrubyfx'

class ASTTreeItem < Java::javafx.scene.control.TreeItem
  include JRubyFX
  
  attr_reader :node
  
  def initialize(node)
    @node = node
    super(node_string)
    set_expanded(true)
  end
  
  def node_string
    node_information = @node.respond_to?(:name) ? ":#{@node.name}" : ""
    "#{@node.node_name}#{node_information} #{@node.position.start_line}"    
  end
  
end

class ASTTreeViewBuilder
  include JRubyFX
  attr_accessor :tree_view
  
  def initialize(tree_view)
    @tree_view = tree_view
  end
  
  def build_tree_item(node)
    ASTTreeItem.new(node)
  end

  def build_view(root)
    @tree_view.root = build_tree_item(root)
    root.child_nodes.each { |child| build_view_inner(child, @tree_view.root) }
  end
  
  def build_view_inner(node, parent_item)
    tree_item = build_tree_item(node)
    parent_item.children << tree_item
    node.child_nodes.each { |child| build_view_inner(child, tree_item) }
  end
  private :build_view_inner
end

if __FILE__ == $0
  require 'jruby'
  root = JRuby.parse("def foo; 42; end; foo")
  builder = ASTTreeViewBuilder.new(nil)
  builder.build_view(root)
end

{'fraction_non_alphanumeric': 0.10580204778156997, 'fraction_numerical': 0.002559726962457338, 'mean_word_length': 3.968220338983051, 'pattern_counts': {'":': 2, '<': 9, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7580313', 'n_tokens_mistral': 885, 'n_tokens_neox': 859, 'n_words': 165}