Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing 'new' class method from interfaces #3275 #3752

Merged
merged 2 commits into from Apr 27, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -438,20 +438,6 @@ public final IRubyObject call(ThreadContext context, IRubyObject self, RubyModul

}

@JRubyMethod(name = "new", rest = true)
public static IRubyObject new_impl(ThreadContext context, IRubyObject self, IRubyObject[] args, Block block) {
final Ruby runtime = context.runtime;

RubyClass implClass = (RubyClass) self.getInstanceVariables().getInstanceVariable("@__implementation");
if (implClass == null) {
implClass = RubyClass.newClass(runtime, runtime.getClass("InterfaceJavaProxy"));
implClass.include(new IRubyObject[] { self });
Helpers.setInstanceVariable(implClass, self, "@__implementation");
}

return Helpers.invoke(context, implClass, "new", args, block);
}

private static JavaClass getJavaClassForInterface(final IRubyObject module) {
return (JavaClass) module.getInstanceVariables().getInstanceVariable("@java_class");
}
Expand Down
15 changes: 15 additions & 0 deletions spec/java_integration/interfaces/interface_new.rb
@@ -0,0 +1,15 @@
require File.dirname(__FILE__) + "/../spec_helper"

describe "what happens with method new on interfaces" do

it "should not be able to instantiate an interface" do
expect{java.lang.Runnable.new}.to raise_error(NoMethodError)
end

it "should not affect impl()" do
@runnable = java.lang.Runnable.impl {a = "Hello"}
expect{@runnable.run}.to_not raise_error(NoMethodError)
expect{@runnable.run}.to eq("Hello")
end

end
22 changes: 11 additions & 11 deletions spec/java_integration/methods/naming_spec.rb
Expand Up @@ -191,37 +191,37 @@

describe "Needed implementation methods for interfaces" do
it "should have __id__ method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("__id__")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("__id__")
end
it "should have __send__ method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("__send__")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("__send__")
end
it "should have == method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("==")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("==")
end
it "should have inspect method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("inspect")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("inspect")
end
it "should have respond_to? method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("respond_to?")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("respond_to?")
end
it "should have class method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("class")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("class")
end
it "should have methods method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("methods")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("methods")
end
it "should have send method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("send")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("send")
end
it "should have equal? method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("equal?")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("equal?")
end
it "should have eql? method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("eql?")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("eql?")
end
it "should have to_s method" do
expect(BeanLikeInterface.new.methods).to have_strings_or_symbols("to_s")
expect(BeanLikeInterface.impl {}.methods).to have_strings_or_symbols("to_s")
end

it "should be able to access Java methods of core Ruby Methods via __method" do
Expand Down