Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: eba14238dd51
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 321205a13a0c
Choose a head ref
  • 4 commits
  • 4 files changed
  • 1 contributor

Commits on Aug 24, 2015

  1. Copy the full SHA
    e28f3f3 View commit details
  2. Copy the full SHA
    c356e3b View commit details
  3. Copy the full SHA
    2844e4a View commit details
  4. Copy the full SHA
    321205a View commit details
Original file line number Diff line number Diff line change
@@ -198,6 +198,9 @@ private static <T extends ParameterTypes> T findMatchingCallableForArgs(final Ru
else { // if ( (Object) moreSpecific == Boolean.FALSE ) {
// none more specific; check for ambiguities
for ( int i = 0; i < msTypes.length; i++ ) {
// TODO if lastArgProc (and we're not dealing with RubyProc.class)
// then comparing last arg should not be needed, right?
// ... same applies for moreSpecificTypes method ...
final Class<?> msType = msTypes[i], cType = cTypes[i];
if ( msType == cType || msType.isAssignableFrom(cType) || cType.isAssignableFrom(msType) ) {
ambiguous = false; break; // continue OUTER;
26 changes: 14 additions & 12 deletions core/src/main/ruby/jruby/java/core_ext/module.rb
Original file line number Diff line number Diff line change
@@ -7,14 +7,17 @@ class Module
# package will become available in this class/module, unless a constant
# with the same name as a Java class is already defined.
#
def include_package(package_name)
def include_package(package)
package = package.package_name if package.respond_to?(:package_name)

if defined? @included_packages
@included_packages << package_name
@included_packages << package
return
end
@included_packages = [package_name]

@included_packages = [ package ]
@java_aliases ||= {}

def self.const_missing(constant)
real_name = @java_aliases[constant] || constant

@@ -23,7 +26,7 @@ def self.const_missing(constant)

@included_packages.each do |package|
begin
java_class = JavaUtilities.get_java_class(package + '.' + real_name.to_s)
java_class = JavaUtilities.get_java_class("#{package}.#{real_name}")
rescue NameError
# we only rescue NameError, since other errors should bubble out
last_error = $!
@@ -44,20 +47,19 @@ def self.const_missing(constant)
end
end
end

# Imports the package specified by +package_name+, first by trying to scan JAR resources
# for the file in question, and failing that by adding a const_missing hook
# to try that package when constants are missing.
def import(package_name, &b)
def import(package_name, &block)
if package_name.respond_to?(:java_class) || (String === package_name && package_name.split(/\./).last =~ /^[A-Z]/)
return super(package_name, &b)
return super(package_name, &block)
end

package_name = package_name.package_name if package_name.respond_to?(:package_name)
return include_package(package_name, &b)
include_package(package_name, &block)
end

def java_alias(new_id, old_id)
@java_aliases[new_id] = old_id
(@java_aliases ||= {})[new_id] = old_id
end

end
6 changes: 2 additions & 4 deletions spec/java_integration/packages/access_spec.rb
Original file line number Diff line number Diff line change
@@ -17,10 +17,8 @@
end

it "can be imported using 'include_package package.module" do
pending "does not work; probably should for consistency?" do
m = Module.new { include_package java.lang }
m::System.should respond_to 'getProperty'
end
m = Module.new { include_package java.lang }
m::System.should respond_to 'getProperty'
end

it "can be imported using 'include_package \"package.module\"'" do
17 changes: 17 additions & 0 deletions test/test_higher_javasupport.rb
Original file line number Diff line number Diff line change
@@ -40,6 +40,23 @@ def test_java_class_loading_and_class_name_collisions
assert_raises(NoMethodError) { Integer.new(10) }
end

def test_java_alias_prior_to_import
mod = Module.new do
java_alias :SYS, 'System'
import 'java.lang'
end
mod::SYS.currentTimeMillis # nothing raised
end

def test_include_package_with_package
mod = Module.new do
include_package java.util.concurrent
include_package Java::JavaUtilConcurrentAtomic
end
mod::ConcurrentSkipListMap.new
mod::AtomicInteger.new(666666)
end

Random = java.util.Random
Double = java.lang.Double
def test_constructors_and_instance_methods