| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | class Method |
|---|
| 22 | |
|---|
| 23 | def name |
|---|
| 24 | method_field=Java::JavaClass.for_name('org.jruby.RubyMethod').declared_field('methodName') |
|---|
| 25 | method_field.accessible=true |
|---|
| 26 | Java::java_to_ruby(method_field.value(Java::ruby_to_java(self))) |
|---|
| 27 | end |
|---|
| 28 | end |
|---|
| 29 | |
|---|
| 30 | class ::SWT::TreeBuilder |
|---|
| 31 | include_class 'org.eclipse.swt.graphics.Image' |
|---|
| 32 | include_class 'org.eclipse.swt.widgets.Display' |
|---|
| 33 | def i(o) |
|---|
| 34 | @@image_cache={} unless defined? @@image_cache |
|---|
| 35 | return @@image_cache[o] if @@image_cache.has_key? o |
|---|
| 36 | res=File.expand_path(File.dirname(__FILE__)+"/../../"+o) |
|---|
| 37 | Image.new Display.getCurrent,res |
|---|
| 38 | end |
|---|
| 39 | end |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | module JRubyUtils |
|---|
| 43 | |
|---|
| 44 | |
|---|
| 45 | |
|---|
| 46 | class RubyObjectBrowser |
|---|
| 47 | class << self |
|---|
| 48 | |
|---|
| 49 | def object_tree(object) |
|---|
| 50 | SWT::Builder.go do |
|---|
| 51 | shell "JRuby Object Viewer by JR - visit http://virtual-void.net" do |
|---|
| 52 | tree(:verticalFill=>true,:horizontalFill=>true) do |
|---|
| 53 | child do |
|---|
| 54 | object {object} |
|---|
| 55 | @object=container do |
|---|
| 56 | label {|o|o.inspect} |
|---|
| 57 | image {i("icons/arrow_right.gif")} |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | child "instance_variables" do |
|---|
| 61 | image {i("icons/flag_blue.gif")} |
|---|
| 62 | children(lambda{|o|o.instance_variables.sort.collect! {|x|{:object=>o,:name=>x} }}) do |
|---|
| 63 | image {i("icons/flag_blue.gif")} |
|---|
| 64 | label {|v|v[:name]} |
|---|
| 65 | child do |
|---|
| 66 | object {|ar| |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | ar[:object].instance_variable_get ar[:name] |
|---|
| 70 | } |
|---|
| 71 | label {|o|o.to_s} |
|---|
| 72 | link {@object} |
|---|
| 73 | end |
|---|
| 74 | end |
|---|
| 75 | end |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | child "methods" do |
|---|
| 79 | image {i("icons/page_text.gif")} |
|---|
| 80 | children(lambda {|o| |
|---|
| 81 | o.methods.sort.collect! do |name| |
|---|
| 82 | {:method=>name,:object=>o} |
|---|
| 83 | end |
|---|
| 84 | }) do |
|---|
| 85 | image {i("icons/page_text.gif")} |
|---|
| 86 | label {|h|h[:method]} |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | conditional lambda{|h| |
|---|
| 90 | (-1..0).include? h[:object].method(h[:method]).arity |
|---|
| 91 | } do |
|---|
| 92 | child do |
|---|
| 93 | object do |h| |
|---|
| 94 | begin |
|---|
| 95 | o=h[:object].dup |
|---|
| 96 | o.send(h[:method]) |
|---|
| 97 | rescue Exception=>exc |
|---|
| 98 | exc |
|---|
| 99 | end |
|---|
| 100 | end |
|---|
| 101 | link {@object} |
|---|
| 102 | end |
|---|
| 103 | end |
|---|
| 104 | end |
|---|
| 105 | end |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | child "class" do |
|---|
| 109 | object {|o|o.class} |
|---|
| 110 | @class=container do |
|---|
| 111 | image {i("icons/icon_component.gif")} |
|---|
| 112 | |
|---|
| 113 | child do |
|---|
| 114 | image {i("icons/icon_component.gif")} |
|---|
| 115 | label{|c|c.to_s} |
|---|
| 116 | child "class_variables" do |
|---|
| 117 | image{i("icons/flag_red.gif")} |
|---|
| 118 | children(lambda{|c|c.class_variables.sort.collect! { |x|{:class=>c,:name=>x}}}) do |
|---|
| 119 | image{i("icons/flag_red.gif")} |
|---|
| 120 | label{|horizontalFill|h[:name]} |
|---|
| 121 | child do |
|---|
| 122 | image{i("icons/arrow_right.gif")} |
|---|
| 123 | label{|horizontalFill|h[:class].class_eval h[:name]} |
|---|
| 124 | end |
|---|
| 125 | end |
|---|
| 126 | end |
|---|
| 127 | link{@object} |
|---|
| 128 | end |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | conditional lambda{|c|c.superclass}do |
|---|
| 132 | child "superclass" do |
|---|
| 133 | image {i("icons/icon_component.gif")} |
|---|
| 134 | object{|c|c.superclass} |
|---|
| 135 | link{@class} |
|---|
| 136 | end |
|---|
| 137 | end |
|---|
| 138 | end |
|---|
| 139 | end |
|---|
| 140 | end |
|---|
| 141 | end |
|---|
| 142 | end |
|---|
| 143 | end |
|---|
| 144 | end |
|---|
| 145 | end |
|---|
| 146 | end |
|---|
| 147 | end |
|---|
| 148 | end |
|---|