# The contents of this file are subject to the Mozilla Public License # Version 1.1 (the "License"); you may not use this file except in # compliance with the License. You may obtain a copy of the License at # http://www.mozilla.org/MPL/ # # Software distributed under the License is distributed on an "AS IS" # basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the # License for the specific language governing rights and limitations # under the License. # # The Initial Developer of the Original Code is Johannes Rudolph. # Portions created by the Initial Developer are Copyright (C) 2006 # the Initial Developer. All Rights Reserved. # # Contributor(s): # Johannes Rudolph require 'java' require 'rubygems' require_gem 'sweetgui' class Method def name method_field=Java::JavaClass.for_name('org.jruby.RubyMethod').declared_field('methodName') method_field.accessible=true Java::java_to_ruby(method_field.value(Java::ruby_to_java(self))) end end module JRubyUtils class NodeHelper include_class 'org.jruby.internal.runtime.methods.DefaultMethod' include_class 'org.jruby.internal.runtime.methods.EvaluateCallable' def NodeHelper.get_method_field return @method_field if @method_field @method_field=Java::JavaClass.for_name('org.jruby.RubyMethod').declared_field('method') @method_field.accessible=true @method_field end def NodeHelper.get_nodes(method) jmethod=Java.ruby_to_java method callable=Java.java_to_ruby(get_method_field.value(jmethod)) return callable.getBody if callable.is_a? DefaultMethod return callable.getNode if callable.is_a? EvaluateCallable end def NodeHelper.get_source_line(file,line) @files={} unless @files unless @files[file] @files[file]=File.open file do |f| f.readlines end end lines=@files[file] lines[line].strip end def NodeHelper.treeify(method) nodes=get_nodes method SWT::Builder.go do shell method.name do tree=tree (:verticalFill=>true,:horizontalFill=>true) do column "Node" column "File" column "Line" column "Code" child method.name do object {nodes} child do @node=container do label {|x|x.getNodeNamePublic} cell(1) {|x|x.getPosition.getFile} cell(2) do |x| pos=x.getPosition "#{pos.getStartLine}-#{pos.getEndLine}" end cell(3) do |node| pos=node.getPosition NodeHelper.get_source_line(pos.getFile,pos.getStartLine) end children(lambda{|x|x.childNodes}) do link {@node} end end end end end end end end end end def wurst puts "Hello World!" end JRubyUtils::NodeHelper.treeify JRubyUtils::NodeHelper.method('wurst')