Guest User

Untitled

a guest
Jul 19th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.23 KB | None | 0 0
  1. diff --git a/lib/rdoc/ri/ri_cache.rb b/lib/rdoc/ri/ri_cache.rb
  2. index 1844ac9..d6a894c 100644
  3. --- a/lib/rdoc/ri/ri_cache.rb
  4. +++ b/lib/rdoc/ri/ri_cache.rb
  5. @@ -185,3 +185,5 @@ module RI
  6.  
  7. end
  8. end
  9. +
  10. +require 'rdoc/ri/jruby_cache'
  11. \ No newline at end of file
  12. diff --git a/lib/rdoc/ri/ri_driver.rb b/lib/rdoc/ri/ri_driver.rb
  13. index a00f20e..64ef852 100644
  14. --- a/lib/rdoc/ri/ri_driver.rb
  15. +++ b/lib/rdoc/ri/ri_driver.rb
  16. @@ -118,7 +118,21 @@ class RiDriver
  17. ######################################################################
  18.  
  19. def process_args
  20. - if @options.list_classes
  21. + if @options.java_classes
  22. + if ARGV.size.zero?
  23. + @display.display_usage
  24. + else
  25. + begin
  26. + require 'rdoc/ri/ri_java'
  27. + ARGV.each do |arg|
  28. + get_java_info_for(arg)
  29. + end
  30. + rescue RiError => e
  31. + STDERR.puts(e.message)
  32. + exit(1)
  33. + end
  34. + end
  35. + elsif @options.list_classes
  36. classes = @ri_reader.full_class_names
  37. @display.list_known_classes(classes)
  38. elsif @options.list_names
  39. diff --git a/lib/rdoc/ri/ri_java.rb b/lib/rdoc/ri/ri_java.rb
  40. new file mode 100644
  41. index 0000000..aea9314
  42. --- /dev/null
  43. +++ b/lib/rdoc/ri/ri_java.rb
  44. @@ -0,0 +1,155 @@
  45. +require 'java'
  46. +require 'rdoc/ri/ri_driver'
  47. +require 'rdoc/ri/ri_reader'
  48. +
  49. +class RiDriver
  50. + def report_java_method_stuff(java_methods)
  51. + method = @ri_reader.get_java_method(java_methods)
  52. + @display.display_method_info(method)
  53. + end
  54. +
  55. + def report_java_class_stuff(cls)
  56. + klass = @ri_reader.get_java_class(cls)
  57. + @display.display_class_info(klass, @ri_reader)
  58. + end
  59. +
  60. + def get_java_info_for(arg)
  61. + cls_name = arg
  62. +
  63. + if arg['#']
  64. + cls_name, mth_name = arg.split '#'
  65. + static = -1
  66. + begin
  67. + cls = java.lang.Class.for_name(cls_name)
  68. + rescue Exception
  69. + raise RiError.new("Nothing known about #{arg}")
  70. + end
  71. + elsif arg['::']
  72. + cls_name, mth_name = arg.split '::'
  73. + static = 1
  74. + begin
  75. + cls = java.lang.Class.for_name(cls_name)
  76. + rescue Exception
  77. + raise RiError.new("Nothing known about #{arg}")
  78. + end
  79. + else
  80. + static = 0
  81. + begin
  82. + cls = java.lang.Class.for_name(cls_name)
  83. + rescue Exception
  84. + begin
  85. + splitted = arg.split('.')
  86. + cls_name = splitted[0..-2].join('.')
  87. + mth_name = splitted[-1]
  88. + cls = java.lang.Class.for_name(cls_name)
  89. + end
  90. + end
  91. + end
  92. +
  93. + if mth_name
  94. + # print method info
  95. + if static == -1 # instance
  96. + methods = cls.methods.select do |m|
  97. + m.name == mth_name &&
  98. + !java.lang.reflect.Modifier.is_static(m.modifiers)
  99. + end
  100. + elsif
  101. + static == 1 # static
  102. + methods = cls.methods.select do |m|
  103. + m.name == mth_name &&
  104. + java.lang.reflect.Modifier.is_static(m.modifiers)
  105. + end
  106. + else # one or other
  107. + last = nil
  108. + methods = cls.methods.select do |m|
  109. + # filter by name
  110. + next false unless m.name == mth_name
  111. +
  112. + # track whether we've seen both static and instance
  113. + static = java.lang.reflect.Modifier.is_static(m.modifiers) ? 1 : -1
  114. + if last && last != static
  115. + raise RiError.new("Ambiguous: try using \# or :: for #{arg}")
  116. + end
  117. + last = static
  118. +
  119. + true
  120. + end
  121. + end
  122. + if !methods || methods.empty?
  123. + raise RiError.new("Nothing known about #{arg}")
  124. + end
  125. +
  126. + report_java_method_stuff(methods)
  127. + else
  128. + report_java_class_stuff(cls)
  129. + end
  130. + end
  131. +end
  132. +
  133. +module RI
  134. + class RiReader
  135. + def get_nice_java_class_name(cls)
  136. + if cls.primitive?
  137. + cls.name
  138. + elsif cls.array?
  139. + "#{get_nice_java_class_name(cls.component_type)}[]"
  140. + else
  141. + cls.name
  142. + end
  143. + end
  144. +
  145. + def get_java_method(java_methods)
  146. + modifier = java.lang.reflect.Modifier
  147. + desc = RI::MethodDescription.new
  148. + is_static = modifier.is_static(java_methods[0].modifiers)
  149. + desc.is_class_method = is_static
  150. + desc.visibility = "public"
  151. + desc.name = java_methods[0].name
  152. + desc.full_name =
  153. + "#{java_methods[0].declaring_class.name}#{is_static ? '.' : '#'}#{desc.name}"
  154. + desc.params = ""
  155. + java_methods.each do |java_method|
  156. + param_strs = java_method.parameter_types.map {|cls| get_nice_java_class_name(cls)}
  157. + desc.params <<
  158. + "#{java_method.name}(#{param_strs.join(',')}) => #{get_nice_java_class_name(java_method.return_type)}\n"
  159. + end
  160. +
  161. + desc
  162. + end
  163. +
  164. + def get_java_class(class_entry)
  165. + desc = RI::ClassDescription.new
  166. +
  167. + desc.full_name = class_entry.name
  168. + desc.superclass = class_entry.superclass.name if class_entry.superclass
  169. +
  170. + # TODO interfaces?
  171. + desc.includes = []
  172. +
  173. + # TODO constants
  174. + desc.constants = []
  175. +
  176. + # TODO bean attributes or something?
  177. + desc.attributes = []
  178. +
  179. + modifier = java.lang.reflect.Modifier
  180. + methods = class_entry.methods
  181. + cls_methods = {}
  182. + methods.select {|m| modifier.is_static(m.modifiers)}.each {|m| cls_methods[m.name] = m}
  183. + inst_methods = {}
  184. + methods.select {|m| !modifier.is_static(m.modifiers)}.each {|m| inst_methods[m.name] = m}
  185. +
  186. + desc.class_methods = []
  187. + cls_methods.keys.each do |name|
  188. + desc.class_methods << RI::MethodSummary.new(name)
  189. + end
  190. +
  191. + desc.instance_methods = []
  192. + inst_methods.keys.each do |name|
  193. + desc.instance_methods << RI::MethodSummary.new(name)
  194. + end
  195. +
  196. + desc
  197. + end
  198. + end
  199. +end
  200. diff --git a/lib/rdoc/ri/ri_options.rb b/lib/rdoc/ri/ri_options.rb
  201. index 179ef96..065555b 100644
  202. --- a/lib/rdoc/ri/ri_options.rb
  203. +++ b/lib/rdoc/ri/ri_options.rb
  204. @@ -22,6 +22,9 @@ module RI
  205. # should we just display a class list and exit
  206. attr_reader :list_classes
  207.  
  208. + # should we look for java classes instead of ruby rdoc
  209. + attr_reader :java_classes
  210. +
  211. # should we display a list of all names
  212. attr_reader :list_names
  213.  
  214. @@ -44,6 +47,9 @@ module RI
  215. "Display the names of classes and modules we\n" +
  216. "know about"],
  217.  
  218. + [ "--java", "-j", nil,
  219. + "Interpret arguments as the names of Java classes\n"],
  220. +
  221. [ "--doc-dir", "-d", "<dirname>",
  222. "A directory to search for documentation. If not\n" +
  223. "specified, we search the standard rdoc/ri directories.\n" +
  224. @@ -227,6 +233,7 @@ module RI
  225. @width = 72
  226. @formatter = RI::TextFormatter.for("plain")
  227. @list_classes = false
  228. + @java_classes = false
  229. @list_names = false
  230.  
  231. # By default all paths are used. If any of these are true, only those
  232. @@ -258,6 +265,7 @@ module RI
  233. when "--list-names" then @list_names = true
  234. when "--no-pager" then @use_stdout = true
  235. when "--classes" then @list_classes = true
  236. + when "--java" then @java_classes = true
  237.  
  238. when "--system" then @use_system = true
  239. when "--site" then @use_site = true
  240. diff --git a/lib/rdoc/ri/ri_paths.rb b/lib/rdoc/ri/ri_paths.rb
  241. index 9768f12..3f92bfa 100644
  242. --- a/lib/rdoc/ri/ri_paths.rb
  243. +++ b/lib/rdoc/ri/ri_paths.rb
  244. @@ -99,3 +99,5 @@ module RI
  245.  
  246. end
  247. end
  248. +
  249. +require 'rdoc/ri/jruby_paths'
  250. \ No newline at end of file
Add Comment
Please, Sign In to add comment