@Deprecated // not used - should go away in >= 9.2 // not intended to be called directly by users (private) // OLD TODO from Ruby code: // This should be implemented in JavaClass.java, where we can // check for reserved Ruby names, conflicting methods, etc. @JRubyMethod(visibility = Visibility.PRIVATE) public static IRubyObject implement(ThreadContext context, IRubyObject self, IRubyObject clazz) { if ( ! (clazz instanceof RubyModule) ) { final Ruby runtime = context.runtime; throw runtime.newTypeError(clazz, runtime.getModule()); } final RubyModule targetModule = (RubyModule) clazz; final JavaClass javaClass = getJavaClassForInterface(self); final Method[] javaInstanceMethods = javaClass.javaClass().getMethods(); final DynamicMethod dummyMethodImpl = new DummyMethodImpl(targetModule); for (int i = 0; i < javaInstanceMethods.length; i++) { final Method javaMethod = javaInstanceMethods[i]; final String name = javaMethod.getName(); if ( targetModule.searchMethod(name).isUndefined() ) { targetModule.addMethod(name, dummyMethodImpl); // only those not-defined } } return context.nil; }
@Deprecated // not used - should go away in >= 9.2 // not intended to be called directly by users (private) // OLD TODO from Ruby code: // This should be implemented in JavaClass.java, where we can // check for reserved Ruby names, conflicting methods, etc. @JRubyMethod(visibility = Visibility.PRIVATE) public static IRubyObject implement(ThreadContext context, IRubyObject self, IRubyObject clazz) { if ( ! (clazz instanceof RubyModule) ) { final Ruby runtime = context.runtime; throw runtime.newTypeError(clazz, runtime.getModule()); } final RubyModule targetModule = (RubyModule) clazz; final JavaClass javaClass = getJavaClassForInterface(self); final Method[] javaInstanceMethods = javaClass.javaClass().getMethods(); final DynamicMethod dummyMethodImpl = new DummyMethodImpl(targetModule); for (int i = 0; i < javaInstanceMethods.length; i++) { final Method javaMethod = javaInstanceMethods[i]; final String name = javaMethod.getName(); if ( targetModule.searchMethod(name).isUndefined() ) { targetModule.addMethod(name, dummyMethodImpl); // only those not-defined } } return context.nil; }
private static void appendFeaturesToClass(ThreadContext context, final IRubyObject self, final RubyClass clazz) { final Ruby runtime = context.runtime; checkAlreadyReified(clazz, runtime); final JavaClass javaClass = getJavaClassForInterface(self); RubyArray javaInterfaces; if ( ! clazz.hasInstanceVariable("@java_interfaces") ) { javaInterfaces = RubyArray.newArray(runtime, javaClass); clazz.setInstanceVariable("@java_interfaces", javaInterfaces); initInterfaceImplMethods(context, clazz); } else { javaInterfaces = (RubyArray) clazz.getInstanceVariable("@java_interfaces"); // we've already done the above priming logic, just add another interface // to the list of intentions unless we're past the point of no return or // already intend to implement the given interface if ( ! ( javaInterfaces.isFrozen() || javaInterfaces.includes(context, javaClass) ) ) { javaInterfaces.append(javaClass); } } }
private static void appendFeaturesToClass(ThreadContext context, final IRubyObject self, final RubyClass clazz) { final Ruby runtime = context.runtime; checkAlreadyReified(clazz, runtime); final JavaClass javaClass = getJavaClassForInterface(self); RubyArray javaInterfaces; if ( ! clazz.hasInstanceVariable("@java_interfaces") ) { javaInterfaces = RubyArray.newArray(runtime, javaClass); clazz.setInstanceVariable("@java_interfaces", javaInterfaces); initInterfaceImplMethods(context, clazz); } else { javaInterfaces = (RubyArray) clazz.getInstanceVariable("@java_interfaces"); // we've already done the above priming logic, just add another interface // to the list of intentions unless we're past the point of no return or // already intend to implement the given interface if ( ! ( javaInterfaces.isFrozen() || javaInterfaces.includes(context, javaClass) ) ) { javaInterfaces.append(javaClass); } } }