Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/lib/rdoc/ri/ri_cache.rb b/lib/rdoc/ri/ri_cache.rb
- index 1844ac9..d6a894c 100644
- --- a/lib/rdoc/ri/ri_cache.rb
- +++ b/lib/rdoc/ri/ri_cache.rb
- @@ -185,3 +185,5 @@ module RI
- end
- end
- +
- +require 'rdoc/ri/jruby_cache'
- \ No newline at end of file
- diff --git a/lib/rdoc/ri/ri_driver.rb b/lib/rdoc/ri/ri_driver.rb
- index a00f20e..64ef852 100644
- --- a/lib/rdoc/ri/ri_driver.rb
- +++ b/lib/rdoc/ri/ri_driver.rb
- @@ -118,7 +118,21 @@ class RiDriver
- ######################################################################
- def process_args
- - if @options.list_classes
- + if @options.java_classes
- + if ARGV.size.zero?
- + @display.display_usage
- + else
- + begin
- + require 'rdoc/ri/ri_java'
- + ARGV.each do |arg|
- + get_java_info_for(arg)
- + end
- + rescue RiError => e
- + STDERR.puts(e.message)
- + exit(1)
- + end
- + end
- + elsif @options.list_classes
- classes = @ri_reader.full_class_names
- @display.list_known_classes(classes)
- elsif @options.list_names
- diff --git a/lib/rdoc/ri/ri_java.rb b/lib/rdoc/ri/ri_java.rb
- new file mode 100644
- index 0000000..aea9314
- --- /dev/null
- +++ b/lib/rdoc/ri/ri_java.rb
- @@ -0,0 +1,155 @@
- +require 'java'
- +require 'rdoc/ri/ri_driver'
- +require 'rdoc/ri/ri_reader'
- +
- +class RiDriver
- + def report_java_method_stuff(java_methods)
- + method = @ri_reader.get_java_method(java_methods)
- + @display.display_method_info(method)
- + end
- +
- + def report_java_class_stuff(cls)
- + klass = @ri_reader.get_java_class(cls)
- + @display.display_class_info(klass, @ri_reader)
- + end
- +
- + def get_java_info_for(arg)
- + cls_name = arg
- +
- + if arg['#']
- + cls_name, mth_name = arg.split '#'
- + static = -1
- + begin
- + cls = java.lang.Class.for_name(cls_name)
- + rescue Exception
- + raise RiError.new("Nothing known about #{arg}")
- + end
- + elsif arg['::']
- + cls_name, mth_name = arg.split '::'
- + static = 1
- + begin
- + cls = java.lang.Class.for_name(cls_name)
- + rescue Exception
- + raise RiError.new("Nothing known about #{arg}")
- + end
- + else
- + static = 0
- + begin
- + cls = java.lang.Class.for_name(cls_name)
- + rescue Exception
- + begin
- + splitted = arg.split('.')
- + cls_name = splitted[0..-2].join('.')
- + mth_name = splitted[-1]
- + cls = java.lang.Class.for_name(cls_name)
- + end
- + end
- + end
- +
- + if mth_name
- + # print method info
- + if static == -1 # instance
- + methods = cls.methods.select do |m|
- + m.name == mth_name &&
- + !java.lang.reflect.Modifier.is_static(m.modifiers)
- + end
- + elsif
- + static == 1 # static
- + methods = cls.methods.select do |m|
- + m.name == mth_name &&
- + java.lang.reflect.Modifier.is_static(m.modifiers)
- + end
- + else # one or other
- + last = nil
- + methods = cls.methods.select do |m|
- + # filter by name
- + next false unless m.name == mth_name
- +
- + # track whether we've seen both static and instance
- + static = java.lang.reflect.Modifier.is_static(m.modifiers) ? 1 : -1
- + if last && last != static
- + raise RiError.new("Ambiguous: try using \# or :: for #{arg}")
- + end
- + last = static
- +
- + true
- + end
- + end
- + if !methods || methods.empty?
- + raise RiError.new("Nothing known about #{arg}")
- + end
- +
- + report_java_method_stuff(methods)
- + else
- + report_java_class_stuff(cls)
- + end
- + end
- +end
- +
- +module RI
- + class RiReader
- + def get_nice_java_class_name(cls)
- + if cls.primitive?
- + cls.name
- + elsif cls.array?
- + "#{get_nice_java_class_name(cls.component_type)}[]"
- + else
- + cls.name
- + end
- + end
- +
- + def get_java_method(java_methods)
- + modifier = java.lang.reflect.Modifier
- + desc = RI::MethodDescription.new
- + is_static = modifier.is_static(java_methods[0].modifiers)
- + desc.is_class_method = is_static
- + desc.visibility = "public"
- + desc.name = java_methods[0].name
- + desc.full_name =
- + "#{java_methods[0].declaring_class.name}#{is_static ? '.' : '#'}#{desc.name}"
- + desc.params = ""
- + java_methods.each do |java_method|
- + param_strs = java_method.parameter_types.map {|cls| get_nice_java_class_name(cls)}
- + desc.params <<
- + "#{java_method.name}(#{param_strs.join(',')}) => #{get_nice_java_class_name(java_method.return_type)}\n"
- + end
- +
- + desc
- + end
- +
- + def get_java_class(class_entry)
- + desc = RI::ClassDescription.new
- +
- + desc.full_name = class_entry.name
- + desc.superclass = class_entry.superclass.name if class_entry.superclass
- +
- + # TODO interfaces?
- + desc.includes = []
- +
- + # TODO constants
- + desc.constants = []
- +
- + # TODO bean attributes or something?
- + desc.attributes = []
- +
- + modifier = java.lang.reflect.Modifier
- + methods = class_entry.methods
- + cls_methods = {}
- + methods.select {|m| modifier.is_static(m.modifiers)}.each {|m| cls_methods[m.name] = m}
- + inst_methods = {}
- + methods.select {|m| !modifier.is_static(m.modifiers)}.each {|m| inst_methods[m.name] = m}
- +
- + desc.class_methods = []
- + cls_methods.keys.each do |name|
- + desc.class_methods << RI::MethodSummary.new(name)
- + end
- +
- + desc.instance_methods = []
- + inst_methods.keys.each do |name|
- + desc.instance_methods << RI::MethodSummary.new(name)
- + end
- +
- + desc
- + end
- + end
- +end
- diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
- index 179ef96..065555b 100644
- --- a/lib/rdoc/ri/ri_options.rb
- +++ b/lib/rdoc/ri/ri_options.rb
- @@ -22,6 +22,9 @@ module RI
- # should we just display a class list and exit
- attr_reader :list_classes
- + # should we look for java classes instead of ruby rdoc
- + attr_reader :java_classes
- +
- # should we display a list of all names
- attr_reader :list_names
- @@ -44,6 +47,9 @@ module RI
- "Display the names of classes and modules we\n" +
- "know about"],
- + [ "--java", "-j", nil,
- + "Interpret arguments as the names of Java classes\n"],
- +
- [ "--doc-dir", "-d", "<dirname>",
- "A directory to search for documentation. If not\n" +
- "specified, we search the standard rdoc/ri directories.\n" +
- @@ -227,6 +233,7 @@ module RI
- @width = 72
- @formatter = RI::TextFormatter.for("plain")
- @list_classes = false
- + @java_classes = false
- @list_names = false
- # By default all paths are used. If any of these are true, only those
- @@ -258,6 +265,7 @@ module RI
- when "--list-names" then @list_names = true
- when "--no-pager" then @use_stdout = true
- when "--classes" then @list_classes = true
- + when "--java" then @java_classes = true
- when "--system" then @use_system = true
- when "--site" then @use_site = true
- diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
- index 9768f12..3f92bfa 100644
- --- a/lib/rdoc/ri/ri_paths.rb
- +++ b/lib/rdoc/ri/ri_paths.rb
- @@ -99,3 +99,5 @@ module RI
- end
- end
- +
- +require 'rdoc/ri/jruby_paths'
- \ No newline at end of file
Add Comment
Please, Sign In to add comment