rjb 1.5.8 → 1.6.3

Sign up to get free protection for your applications and to get access to all the features.
data/ext/rjbexception.c CHANGED
@@ -29,7 +29,7 @@
29
29
  static VALUE missing_delegate(int argc, VALUE* argv, VALUE self)
30
30
  {
31
31
  ID rmid = rb_to_id(argv[0]);
32
- return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
32
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1);
33
33
  }
34
34
 
35
35
  static VALUE get_cause(VALUE self)
@@ -37,6 +37,26 @@ static VALUE get_cause(VALUE self)
37
37
  return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rb_intern("cause"), 0);
38
38
  }
39
39
 
40
+ static VALUE ex_respond_to(int argc, VALUE* argv, VALUE self)
41
+ {
42
+ if (argc < 1 || argc > 2)
43
+ {
44
+ rb_raise(rb_eArgError, "respond_to? require 1 or 2 arguments");
45
+ }
46
+ if (rb_to_id(argv[0]) == rb_intern("to_str"))
47
+ {
48
+ return Qfalse;
49
+ }
50
+ else if (rb_to_id(argv[0]) == rb_intern("exception"))
51
+ {
52
+ return Qtrue;
53
+ }
54
+ else
55
+ {
56
+ return rb_funcallv(rb_ivar_get(self, rb_intern("@cause")), rb_intern("respond_to?"), argc, argv);
57
+ }
58
+ }
59
+
40
60
  /*
41
61
  * handle Java exception
42
62
  * At this time, the Java exception is defined without the package name.
@@ -67,6 +87,7 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
67
87
  rexp = rb_define_class(pcls, rb_eStandardError);
68
88
  rb_define_method(rexp, "cause", get_cause, 0);
69
89
  rb_define_method(rexp, "method_missing", missing_delegate, -1);
90
+ rb_define_method(rexp, "respond_to?", ex_respond_to, -1);
70
91
  #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS)
71
92
  rb_hash_aset(rjb_loaded_classes, cname, rexp);
72
93
  #else
@@ -76,7 +97,7 @@ VALUE rjb_get_exception_class(JNIEnv* jenv, jstring str)
76
97
  st_insert(RHASH(rjb_loaded_classes)->tbl, cname, rexp);
77
98
  #endif
78
99
  #endif
79
-
100
+
80
101
  }
81
102
  return rexp;
82
103
  }
@@ -88,7 +109,7 @@ VALUE rjb_s_throw(int argc, VALUE* argv, VALUE self)
88
109
  {
89
110
  VALUE klass;
90
111
  VALUE message;
91
- JNIEnv* jenv = NULL;
112
+ JNIEnv* jenv = NULL;
92
113
 
93
114
  rjb_load_vm_default();
94
115
 
data/lib/rjb.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  =begin
2
- Copyright(c) 2006-2010,2012 arton
2
+ Copyright(c) 2006-2010,2012,2020 arton
3
3
  =end
4
4
 
5
5
  require 'rbconfig'
@@ -86,7 +86,7 @@ module Rjb
86
86
  (org + klass.getMethods.select do |m|
87
87
  blk.call(m)
88
88
  end.map do |m|
89
- m.name
89
+ m.name.to_sym
90
90
  end).uniq
91
91
  end
92
92
  def format_sigs(s)
@@ -98,6 +98,19 @@ module Rjb
98
98
  "[#{s.map{|m|m.nil? ? 'void' : m}.join(', ')}]"
99
99
  end
100
100
  end
101
+ def make_snake(nm)
102
+ nm.gsub(/(.)([A-Z])/) { "#{$1}_#{$2.downcase}" }
103
+ end
104
+ alias :rjb_org_respond_to? :respond_to?
105
+ def rjb_respond_to?(sym, klass, priv)
106
+ return true if (klass ? self : getClass).getMethods.select do |m|
107
+ (klass && !instance_method?(m) && (priv || public_method?(m))) ||
108
+ (!klass && instance_method?(m) && (priv || public_method?(m)))
109
+ end.map do |m|
110
+ [m.name.to_sym, make_snake(m.name).to_sym]
111
+ end.flatten.include?(sym.to_sym)
112
+ rjb_org_respond_to?(sym, priv)
113
+ end
101
114
  end
102
115
 
103
116
  class Rjb_JavaClass
@@ -119,6 +132,9 @@ module Rjb
119
132
  "#{m}(#{format_sigs(self.static_sigs(m))})"
120
133
  end
121
134
  end
135
+ def respond_to?(sym, priv = false)
136
+ rjb_respond_to?(sym, true, priv)
137
+ end
122
138
  end
123
139
  class Rjb_JavaProxy
124
140
  include JMethod
@@ -141,6 +157,9 @@ module Rjb
141
157
  "#{m}(#{format_sigs(getClass.sigs(m))})"
142
158
  end
143
159
  end
160
+ def respond_to?(sym, priv = false)
161
+ rjb_respond_to?(sym, false, priv)
162
+ end
144
163
  end
145
164
  class Rjb_JavaBridge
146
165
  def method_missing(name, *args)
data/test/test.rb CHANGED
@@ -216,17 +216,28 @@ class TestRjb < Test::Unit::TestCase
216
216
  end
217
217
 
218
218
  def test_combination_charcters
219
- teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84\xed\xa1\xa9\xed\xba\xb2\xe3\x81\x8b\xe3\x82\x9a"
219
+ teststr = "\xc7\x96\xc3\xbc\xcc\x84\x75\xcc\x88\xcc\x84𪚲\xe3\x81\x8b\xe3\x82\x9a"
220
220
  test = import('jp.co.infoseek.hp.arton.rjb.Test').new
221
221
  s = test.getUmlaut()
222
222
  if Object::const_defined?(:Encoding) #>=1.9
223
- teststr = teststr.force_encoding(Encoding::UTF_8)
224
- assert_equal(s, teststr)
223
+ =begin
224
+ n = [teststr.bytes.length, s.bytes.length].max
225
+ puts "org:#{teststr.bytes.length}, ret:#{s.bytes.length}"
226
+ 0.upto(n - 1) do |i|
227
+ b0 = teststr.getbyte(i)
228
+ b0 = 0 unless b0
229
+ b1 = s.getbyte(i)
230
+ b1 = 0 unless b1
231
+ puts sprintf("%02X - %02X\n", b0, b1)
232
+ end
233
+ =end
234
+ assert_equal(teststr.bytes.length, s.bytes.length)
235
+ assert_equal(teststr, s)
225
236
  else
226
237
  default_kcode = $KCODE
227
238
  begin
228
239
  $KCODE = "utf8"
229
- assert_equal(s, teststr)
240
+ assert_equal(teststr, s)
230
241
  ensure
231
242
  $KCODE = default_kcode
232
243
  end
@@ -715,19 +726,19 @@ class TestRjb < Test::Unit::TestCase
715
726
  end
716
727
  def test_methods_extension
717
728
  m = @jString.new('').methods
718
- assert m.include?('indexOf')
729
+ assert m.include?(:indexOf)
719
730
  end
720
731
  def test_class_methods_extension
721
732
  m = @jString.methods
722
- assert m.include?('format')
733
+ assert m.include?(:format)
723
734
  end
724
735
  def test_pmethods_extension
725
736
  m = @jString.new('').public_methods
726
- assert m.include?('indexOf')
737
+ assert m.include?(:indexOf)
727
738
  end
728
739
  def test_class_pmethods_extension
729
740
  m = @jString.public_methods
730
- assert m.include?('format')
741
+ assert m.include?(:format)
731
742
  end
732
743
  def test_java_methods
733
744
  indexof = @jString.new('').java_methods.find do |m|
@@ -947,5 +958,22 @@ class TestRjb < Test::Unit::TestCase
947
958
  end
948
959
  end
949
960
  end
950
- end
951
961
 
962
+ def test_java_utf8
963
+ y = @jString.new('𠮷野家')
964
+ assert_equal '𠮷野家', y.toString
965
+ end
966
+
967
+ def test_respond_to
968
+ str = @jString.new('blabla')
969
+ assert str.respond_to? :substring
970
+ assert_false str.respond_to? :unknown_method
971
+ begin
972
+ @jInteger.parseInt('blabla')
973
+ rescue => e
974
+ assert e.respond_to? :print_stack_trace
975
+ assert e.respond_to? :printStackTrace
976
+ assert_false e.respond_to? :unknown_method
977
+ end
978
+ end
979
+ end
metadata CHANGED
@@ -1,19 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rjb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.8
4
+ version: 1.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - arton
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-17 00:00:00.000000000 Z
11
+ date: 2021-02-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: 'RJB is a bridge program that connect between Ruby and Java with Java
13
+ description: RJB is a Bridge library which connects Ruby and Java code using the Java
14
14
  Native Interface.
15
-
16
- '
17
15
  email: artonx@gmail.com
18
16
  executables: []
19
17
  extensions:
@@ -22,9 +20,10 @@ extra_rdoc_files: []
22
20
  files:
23
21
  - COPYING
24
22
  - ChangeLog
23
+ - README.md
25
24
  - data/rjb/jp/co/infoseek/hp/arton/rjb/RBridge.class
26
25
  - ext/RBridge.java
27
- - ext/depend
26
+ - ext/depend.erb
28
27
  - ext/extconf.h
29
28
  - ext/extconf.rb
30
29
  - ext/jniwrap.h
@@ -72,11 +71,11 @@ files:
72
71
  - test/test_osxload.rb
73
72
  - test/test_unload.rb
74
73
  - test/x.rb
75
- homepage: https://www.artonx.org/collabo/backyard/?RubyJavaBridge
74
+ homepage: http://www.artonx.org/collabo/backyard/?RubyJavaBridge
76
75
  licenses:
77
- - LGPL
76
+ - LGPL-2.1-or-later
78
77
  metadata: {}
79
- post_install_message:
78
+ post_install_message:
80
79
  rdoc_options: []
81
80
  require_paths:
82
81
  - lib
@@ -91,11 +90,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
90
  - !ruby/object:Gem::Version
92
91
  version: '0'
93
92
  requirements:
94
- - none
95
93
  - JDK 5.0
96
- rubygems_version: 3.0.1
97
- signing_key:
94
+ rubygems_version: 3.2.3
95
+ signing_key:
98
96
  specification_version: 4
99
- summary: Ruby Java bridge
100
- test_files:
101
- - test/test.rb
97
+ summary: Ruby Java Bridge
98
+ test_files: []