Skip to content

Commit 6eda76f

Browse files
committed
make loading "old" java ext .rb parts safe + prepare to use them for (yard) doc
1 parent 3e1a3ea commit 6eda76f

File tree

5 files changed

+514
-224
lines changed

5 files changed

+514
-224
lines changed

core/src/main/ruby/jruby/java/java_ext/java.io.rb

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,28 @@
33
# this file is no longer loaded but is kept to provide doc stubs
44

55
class Java::java::io::InputStream
6+
# Convert a Java input stream to a Ruby `IO`.
7+
# @option opts [Types] autoclose changes `IO#autoclose=` if set
8+
# @return [IO]
69
def to_io(opts = nil)
7-
ruby_io = org.jruby.RubyIO.new(JRuby.runtime, self)
8-
if opts && !opts[:autoclose]
9-
ruby_io.setAutoclose(false)
10-
end
11-
JRuby.dereference(ruby_io)
10+
# stub implemented in org.jruby.javasupport.ext.JavaIo.java
1211
end
13-
end
12+
end if false
1413

1514
class Java::java::io::OutputStream
15+
# Convert a Java output stream to a Ruby `IO`.
16+
# @option opts [Types] autoclose changes `IO#autoclose=` if set
17+
# @return [IO]
1618
def to_io(opts = nil)
17-
ruby_io = org.jruby.RubyIO.new(JRuby.runtime, self)
18-
if opts && !opts[:autoclose]
19-
ruby_io.setAutoclose(false)
20-
end
21-
JRuby.dereference(ruby_io)
19+
# stub implemented in org.jruby.javasupport.ext.JavaIo.java
2220
end
23-
end
21+
end if false
2422

2523
module Java::java::nio::channels::Channel
24+
# Convert a Java channel to a Ruby `IO`.
25+
# @option opts [Types] autoclose changes `IO#autoclose=` if set
26+
# @return [IO]
2627
def to_io(opts = nil)
27-
ruby_io = org.jruby.RubyIO.new(JRuby.runtime, self)
28-
if opts && !opts[:autoclose]
29-
ruby_io.setAutoclose(false)
30-
end
31-
JRuby.dereference(ruby_io)
28+
# stub implemented in org.jruby.javasupport.ext.JavaIo.java
3229
end
33-
end
30+
end if false

core/src/main/ruby/jruby/java/java_ext/java.lang.rb

Lines changed: 72 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -32,93 +32,99 @@ def static?
3232
# *java.lang.Runnable* instances allow for a `to_proc` conversion.
3333
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/Runnable.html
3434
module Java::java::lang::Runnable
35+
# @return [Proc] calling #run when caled
3536
def to_proc
36-
proc { self.run }
37+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
38+
# proc { self.run }
3739
end
38-
end
40+
end if false
3941

4042
# A `java.lang.Iterable` will act like a Ruby `Enumerable`.
4143
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/Iterable.html
4244
module Java::java::lang::Iterable
4345
include ::Enumerable
4446

45-
def each
46-
iter = iterator
47-
yield(iter.next) while iter.hasNext
47+
# Ruby style `Enumerable#each` iteration for Java iterable types.
48+
# @return [Enumerator] if called without a block to yield to
49+
def each(&block)
50+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
51+
# iter = iterator
52+
# yield(iter.next) while iter.hasNext
4853
end
4954

50-
def each_with_index
51-
index = 0
52-
iter = iterator
53-
while iter.hasNext
54-
yield(iter.next, index)
55-
index += 1
56-
end
55+
# Ruby style `Enumerable#each_with_index` for Java iterable types.
56+
# @return [Enumerator] if called without a block to yield to
57+
def each_with_index(&block)
58+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
59+
# index = 0
60+
# iter = iterator
61+
# while iter.hasNext
62+
# yield(iter.next, index)
63+
# index += 1
64+
# end
5765
end
58-
end
66+
end if false
5967

6068
# *java.lang.Comparable* mixes in Ruby's `Comparable` support.
6169
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/Comparable.html
6270
module Java::java::lang::Comparable
6371
include ::Comparable
6472

6573
def <=>(a)
66-
return nil if a.nil?
67-
compareTo(a)
74+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
75+
# return nil if a.nil?
76+
# compareTo(a)
6877
end
69-
end
78+
end if false
7079

7180
# Java's *java.lang.Throwable* (exception/errors) classes resemble Ruby's `Exception`.
7281
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/Throwable.html
7382
class Java::java::lang::Throwable
7483

84+
# @return [Array] the mapped stack-trace
7585
def backtrace
76-
stack_trace.map(&:to_s)
86+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
87+
# stack_trace.map(&:to_s)
7788
end
7889

79-
# @note Noop as Java exceptions can not change trace.
90+
# @note Noop as Java exceptions can not change their stack-trace.
8091
def set_backtrace(trace)
92+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
8193
end
8294

8395
# Always a non-nil to follow Ruby's {Exception#message} conventions.
8496
# @note getMessage still returns nil, when no message was given for the Java exception!
8597
# @return [String]
8698
def message
87-
getLocalizedMessage || ''
99+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
100+
# getLocalizedMessage || ''
88101
end
89102

90103
def to_s
91-
message
104+
# message
92105
end
93106

94107
def inspect
95-
to_string
108+
# to_string
96109
end
97110

98-
class << self
99-
alias :old_eqq :===
100-
def ===(rhs)
101-
if (NativeException == rhs.class) && (java_class.assignable_from?(rhs.cause.java_class))
102-
true
103-
else
104-
old_eqq(rhs)
105-
end
106-
end
111+
def self.===(ex)
112+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
107113
end
108-
end
114+
115+
end if false
109116

110117
class Java::java::lang::Character
111-
java_alias :isJavaIdentifierStart_char, :isJavaIdentifierStart, [Java::char]
112-
java_alias :isJavaIdentifierPart_char, :isJavaIdentifierPart, [Java::char]
113118

114-
def self.java_identifier_start?(fixnum)
115-
isJavaIdentifierStart_char(fixnum);
119+
def self.java_identifier_start?(char)
120+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
116121
end
117122

118-
def self.java_identifier_part?(fixnum)
119-
isJavaIdentifierPart_char(fixnum);
123+
def self.java_identifier_part?(char)
124+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
120125
end
121-
end
126+
127+
end if false
122128

123129
# *java.lang.Class*
124130
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html
@@ -128,55 +134,60 @@ class Java::java::lang::Class
128134
include ::JavaUtilities::ModifierShortcuts
129135

130136
def ruby_class
131-
::JRuby.runtime.java_support.get_proxy_class_from_cache(self)
137+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
138+
# ::JRuby.runtime.java_support.get_proxy_class_from_cache(self)
132139
end
133140

134141
alias to_s name
135142

136143
def inspect
137-
"class #{name}"
144+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
138145
end
139146

140147
def resource_as_string(name)
141-
resource_as_stream(name).to_io.read
148+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
149+
# resource_as_stream(name).to_io.read
142150
end
143151

144152
alias annotation get_annotation
145153

146154
def annotations?
147-
!annotations.empty?
155+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
156+
# !annotations.empty?
148157
end
149158

150159
def declared_annotations?
151-
!declared_annotations.empty?
160+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
161+
# !declared_annotations.empty?
152162
end
153163

154164
alias annotation_present? is_annotation_present
155165

156166
def <=>(other)
157-
return nil unless other.class == java::lang::Class
158-
159-
return 0 if self == other
160-
return 1 if self.is_assignable_from(other)
161-
return -1 if other.is_assignable_from(self)
167+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
168+
# return nil unless other.class == java::lang::Class
169+
#
170+
# return 0 if self == other
171+
# return 1 if self.is_assignable_from(other)
172+
# return -1 if other.is_assignable_from(self)
162173
end
163174

164175
def java_instance_methods
165-
methods.select {|m| !Modifier.is_static(m.modifiers)}.freeze
176+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
166177
end
167178

168179
def declared_instance_methods
169-
declared_methods.select {|m| !Modifier.is_static(m.modifiers)}.freeze
180+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
170181
end
171182

172183
def java_class_methods
173-
methods.select {|m| Modifier.is_static(m.modifiers)}.freeze
184+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
174185
end
175186

176187
def declared_class_methods
177-
declared_methods.select {|m| Modifier.is_static(m.modifiers)}.freeze
188+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
178189
end
179-
end
190+
end if false
180191

181192
# *java.lang.ClassLoader*
182193
# @see http://docs.oracle.com/javase/8/docs/api/java/lang/ClassLoader.html
@@ -185,31 +196,32 @@ class Java::java::lang::ClassLoader
185196
alias resource_as_url get_resource
186197

187198
def resource_as_string(name)
188-
resource_as_stream(name).to_io.read
199+
# stub implemented in org.jruby.javasupport.ext.JavaLang.java
200+
# resource_as_stream(name).to_io.read
189201
end
190-
end
202+
end if false
191203

192204
class Java::java::lang::reflect::AccessibleObject
193205
include ::JavaUtilities::ModifierShortcuts
194206

195207
alias inspect to_s
196-
end
208+
end if false
197209

198210
class Java::java::lang::reflect::Constructor
199211
def return_type
200212
nil
201213
end
202214

203215
alias argument_types parameter_types
204-
end
216+
end if false
205217

206218
class Java::java::lang::reflect::Method
207219
def invoke_static(*args)
208220
invoke(nil, *args)
209221
end
210222

211223
alias argument_types parameter_types
212-
end
224+
end if false
213225

214226
class Java::java::lang::reflect::Field
215227
alias value_type name
@@ -223,7 +235,7 @@ def static_value
223235
def set_static_value(val)
224236
set(nil, val)
225237
end
226-
end
238+
end if false
227239

228240
Java::byte[].class_eval do
229241
def ubyte_get(index)
@@ -236,4 +248,4 @@ def ubyte_set(index, value)
236248
value -= 256 if value > 127
237249
self[index] = value
238250
end
239-
end
251+
end if false
Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
# NOTE: these Ruby extensions were moved to native code!
2-
# @see org.jruby.javasupport.ext.JavaIo.java
2+
# @see org.jruby.javasupport.ext.JavaNet.java
33
# this file is no longer loaded but is kept to provide doc stubs
44

55
class Java::java::net::URL
6-
def open(*rest, &block)
7-
stream = openStream
8-
io = stream.to_io
9-
if block
10-
begin
11-
block.call(io)
12-
ensure
13-
stream.close
14-
end
15-
else
16-
io
17-
end
6+
# Open the URL stream and yield it as a Ruby `IO`.
7+
# @return [IO] if no block given, otherwise yielded result
8+
def open(&block)
9+
# stub implemented in org.jruby.javasupport.ext.JavaNet.java
10+
# stream = openStream
11+
# io = stream.to_io
12+
# if block
13+
# begin
14+
# block.call(io)
15+
# ensure
16+
# stream.close
17+
# end
18+
# else
19+
# io
20+
# end
1821
end
19-
end
22+
end if false

0 commit comments

Comments
 (0)