lib/ruboto/util/xml_element.rb in ruboto-0.9.0 vs lib/ruboto/util/xml_element.rb in ruboto-0.10.0.rc.0

- old
+ new

@@ -149,11 +149,11 @@ rv = super_string return "{#{rv} return;}" unless attribute("return") rv ? "return #{rv}" : default_return end - def ruby_call(on_ruby_instance = false, camelize = false) + def ruby_call(camelize = false) params = parameters args = "" if params.size > 1 args = ", new Object[]{" + params.map{|i| i[0]}.join(", ") + "}" elsif params.size > 0 @@ -173,11 +173,10 @@ end return_cast = "return (#{return_class.gsub("&lt;", "<").gsub("&gt;", ">")}) " if return_class convert_return = "#{return_class.sub(/<.*>$/, '')}.class, " end - if on_ruby_instance method_name = camelize ? attribute("name") : snake_case_attribute global_args = params.map{|i| "$arg_#{i[0]}"}.join(", ") ["// FIXME(uwe): Simplify when we stop support for RubotoCore 0.4.7"] + if_else( "JRubyAdapter.isJRubyPreOneSeven()", @@ -190,47 +189,35 @@ "JRubyAdapter.isJRubyOneSeven()", ["#{return_cast}JRubyAdapter.runRubyMethod(#{convert_return}scriptInfo.getRubyInstance(), \"#{method_name}\"#{args});"], ['throw new RuntimeException("Unknown JRuby version: " + JRubyAdapter.get("JRUBY_VERSION"));'] ) ) - else - ["#{return_cast}JRubyAdapter.runRubyMethod(#{convert_return}scriptInfo.getCallbackProcs()[#{constant_string}], \"call\" #{args});"] - end end def snake_case_attribute attribute("name").gsub(/[A-Z]/) { |i| "_#{i}" }.downcase end def method_definition(class_name) method_call( (attribute("return") ? attribute("return") : "void"), attribute("name"), parameters, - get_elements('exception').map{|m| m.attribute('type')}, + get_elements('exception').map { |m| m.attribute('type') }, ["if (ScriptLoader.isCalledFromJRuby()) #{super_return}", - if_else( - "JRubyAdapter.isInitialized()", - if_else( - "scriptInfo.getCallbackProcs() != null && scriptInfo.getCallbackProcs()[#{constant_string}] != null", - [super_string] + ruby_call, - ['String rubyClassName = scriptInfo.getRubyClassName();'] + - if_else( - # TODO(uwe): Remove defined?(rubyClassName) if we remove non-class-based class definitions - "(Boolean)JRubyAdapter.runScriptlet(\"defined?(\" + rubyClassName + \") == 'constant' && \" + rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{snake_case_attribute}}\")", - ruby_call(true), - if_else( - # TODO(uwe): Remove defined?(rubyClassName) if we remove non-class-based class definitions - "(Boolean)JRubyAdapter.runScriptlet(\"defined?(\" + rubyClassName + \") == 'constant' && \" + rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{attribute('name')}}\")", - ruby_call(true, true), - [super_return] - ) - ) - ), - [ - %Q{Log.i("Method called before JRuby runtime was initialized: #{class_name}##{attribute('name')}");}, - super_return, - ] - ) + if_else("!JRubyAdapter.isInitialized()", + [%Q{Log.i("Method called before JRuby runtime was initialized: #{class_name}##{attribute('name')}");}, + super_return]), + 'String rubyClassName = scriptInfo.getRubyClassName();', + "if (rubyClassName == null) #{super_return}", + if_else( + "(Boolean)JRubyAdapter.runScriptlet(rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{snake_case_attribute}}\")", + ruby_call, + if_else( + "(Boolean)JRubyAdapter.runScriptlet(rubyClassName + \".instance_methods(false).any?{|m| m.to_sym == :#{attribute('name')}}\")", + ruby_call(true), + [super_return] + ) + ) ] ).indent.join("\n") end def constructor_definition(class_name)