Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ji] support 'native' method arguments (e.g. org.jruby.RubyObject)
Browse files Browse the repository at this point in the history
for (backwards) safety this has lower priority than an exact match
and thus is not expected to cause any regressions
kares committed Jan 19, 2017
1 parent 5f85cb8 commit d10afc4
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -594,7 +594,9 @@ private static boolean assignableAndPrimitivableWithVarargs(ParameterTypes param
}

private static boolean assignable(Class<?> type, final IRubyObject arg) {
return JavaClass.assignable(type, getJavaClass(arg));
return JavaClass.assignable(type, getJavaClass(arg)) ||
// handle 'native' signatures e.g. method with a (org.jruby.RubyArray arg)
( arg != null && type.isAssignableFrom(arg.getClass()) );
}

/**
15 changes: 15 additions & 0 deletions test/jruby/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -1549,6 +1549,21 @@ def x.foo; end
assert(x.java_class.kind_of?Java::JavaClass)
end

java_import 'org.jruby.javasupport.test.name.Sample'

def test_native_ruby_array_java_argument
assert_equal '10', Sample.test(16)
assert_equal 3, Sample.test([1, 2.0, 3])
end

def test_ruby_object_java_argument
assert_equal 'RubyString', Sample.rubyObj('s')
assert_equal 'RubyInteger', Sample.rubyObj(100)
assert_equal 'RubyObject', Sample.rubyObj([1])
# undefined territory as nil gets into null early
#assert_equal 'RubyObject', Sample.rubyObj(nil)
end

# JRUBY-4524
class IncludePackageSuper
def self.const_missing(a)
25 changes: 25 additions & 0 deletions test/org/jruby/javasupport/test/name/Sample.java
Original file line number Diff line number Diff line change
@@ -8,4 +8,29 @@ public Sample(int param) { // @see test_backtraces.rb
throw new IllegalStateException("param == -1");
}
}

public static String test(int x) {
return Integer.toHexString(x);
}

public static Object test(org.jruby.RubyArray array) {
return array.length();
}

public static String rubyObj(org.jruby.RubyString obj) {
return "RubyString";
}

public static String rubyObj(org.jruby.RubyInteger obj) {
return "RubyInteger";
}

public static String rubyObj(org.jruby.RubyObject obj) {
return "RubyObject";
}

public static String rubyObj(java.lang.Object obj) {
return "";
}

}

0 comments on commit d10afc4

Please sign in to comment.