Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/ruby/shared/jruby/compiler/java_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,8 @@ def constructor?
end

def new_method(name, java_signature = nil, annotations = [])
is_constructor = name == "initialize"
is_constructor = name == "initialize" ||
java_signature.is_a?(Java::OrgJrubyAstJava_signature::ConstructorSignatureNode)
@has_constructor ||= is_constructor

if is_constructor
Expand Down
30 changes: 28 additions & 2 deletions spec/java_integration/jrubyc/java/constructor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,32 @@ def generate(script)
end

describe "with an initialize method" do
describe "and a constructor java_signature on a another method" do
it "generates a default constructor" do
cls = generate("class Foo; def initialize(a); end; java_signature 'Foo()'; def default_cnstr(); end; end").classes[0]
cls.constructor?.should be true

init = cls.methods[0]
init.should_not be nil
init.name.should == "initialize"
init.constructor?.should == true
init.java_signature.to_s.should == "Object initialize(Object a)"
init.args.length.should == 1

java = init.to_s
java.should match OBJECT_INITIALIZE_PATTERN

def_cnstr = cls.methods[1]
def_cnstr.should_not be nil
def_cnstr.constructor?.should == true
def_cnstr.java_signature.to_s.should == "Foo()"
def_cnstr.args.length.should == 0

java = def_cnstr.to_s
java.should match EMPTY_INITIALIZE_PATTERN
end
end

describe "with no arguments" do
it "generates a default constructor" do
cls = generate("class Foo; def initialize; end; end").classes[0]
Expand Down Expand Up @@ -91,8 +117,8 @@ def generate(script)
cls = generate("class Foo; java_signature 'Foo() throws FooBarException,QuxBazException'; def initialize(); end; end").classes[0]

method = cls.methods[0]
method.java_signature.to_s.should == 'Foo() throws FooBarException, QuxBazException'
end
method.java_signature.to_s.should == 'Foo() throws FooBarException, QuxBazException'
end
end

end
Expand Down