Class: JRubyUtils::RubyObjectBrowser

Inherits:
Object
  • Object
show all
Defined in:
lib/apps/objecttree.rb

Overview

A Browser of objects for JRuby

Class Method Summary collapse

Class Method Details

.object_tree(object) ⇒ Object

Builds a tree which shows the structure of the given object


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/apps/objecttree.rb', line 49

def object_tree(object)
  SWT::Builder.go do
    shell "JRuby Object Viewer by JR - visit http://virtual-void.net" do
      tree(:verticalFill=>true,:horizontalFill=>true) do
        child do
          object {object}
          @object=container do
            label {|o|o.inspect}
            image {i("icons/arrow_right.gif")}

            # instance variables node
            child "instance_variables" do
              image {i("icons/flag_blue.gif")}
              children(lambda{|o|o.instance_variables.sort.collect! {|x|{:object=>o,:name=>x}  }}) do
                image {i("icons/flag_blue.gif")}
                label {|v|v[:name]}
                child do
                  object {|ar|
                    #puts "Object: #{ar}"
                    #name.last.instance_variable_get name
                    ar[:object].instance_variable_get ar[:name]
                  }
                  label {|o|o.to_s}
                  link {@object}
                end
              end
            end

            # methods node
            child "methods" do
              image {i("icons/page_text.gif")}
              children(lambda {|o|
                         o.methods.sort.collect! do |name|
                           {:method=>name,:object=>o}
                         end
                       }) do
                image {i("icons/page_text.gif")}
                label {|h|h[:method]}

                # execute method if it has no arguments
                conditional lambda{|h|
                  (-1..0).include? h[:object].method(h[:method]).arity
                } do
                  child do
                    object do |h|
                      begin
                        o=h[:object].dup
                        o.send(h[:method])
                      rescue Exception=>exc
                        exc
                      end
                    end
                    link {@object}
                  end
                end
              end
            end

            # class node
            child "class" do
              object {|o|o.class}
              @class=container do
                image {i("icons/icon_component.gif")}

                child do
                  image {i("icons/icon_component.gif")}
                  label{|c|c.to_s}
                  child "class_variables" do
                    image{i("icons/flag_red.gif")}
                    children(lambda{|c|c.class_variables.sort.collect! { |x|{:class=>c,:name=>x}}}) do
                      image{i("icons/flag_red.gif")}
                      label{|horizontalFill|h[:name]}
                      child do
                        image{i("icons/arrow_right.gif")}
                        label{|horizontalFill|h[:class].class_eval h[:name]}
                      end
                    end
                  end
                  link{@object}
                end

                # superclass node if appropriate
                conditional lambda{|c|c.superclass}do
                  child "superclass" do
                    image {i("icons/icon_component.gif")}
                    object{|c|c.superclass}
                    link{@class}
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end