本文整理汇总了Java中org.jruby.javasupport.JavaEmbedUtils.javaToRuby方法的典型用法代码示例。如果您正苦于以下问题:Java JavaEmbedUtils.javaToRuby方法的具体用法?Java JavaEmbedUtils.javaToRuby怎么用?Java JavaEmbedUtils.javaToRuby使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jruby.javasupport.JavaEmbedUtils
的用法示例。
在下文中一共展示了JavaEmbedUtils.javaToRuby方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resultsCapturesJavaError
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Test(enabled = false) public void resultsCapturesJavaError() throws Exception {
RubyScript script = new RubyScript(out, err, converToCode(SCRIPT_CONTENTS_ERROR_FROM_JAVA),
new File(System.getProperty(Constants.PROP_PROJECT_DIR), "dummyfile.rb").getAbsolutePath(), false, null,
Constants.FRAMEWORK_SWING);
script.setDriverURL("");
Ruby interpreter = script.getInterpreter();
assertTrue("Collector not defined", interpreter.isClassDefined("Collector"));
RubyClass collectorClass = interpreter.getClass("Collector");
IRubyObject presult = JavaEmbedUtils.javaToRuby(interpreter, result);
IRubyObject collector = collectorClass.newInstance(interpreter.getCurrentContext(), new IRubyObject[0], new Block(null));
IRubyObject rubyObject = interpreter.evalScriptlet("proc { my_function }");
try {
collector.callMethod(interpreter.getCurrentContext(), "callprotected", new IRubyObject[] { rubyObject, presult });
} catch (Throwable t) {
}
assertEquals(1, result.failureCount());
Failure[] failures = result.failures();
assertTrue("Should end with TestRubyScript.java. but has " + failures[0].getTraceback()[0].fileName,
failures[0].getTraceback()[0].fileName.endsWith("TestRubyScript.java"));
assertEquals("throwError", failures[0].getTraceback()[0].functionName);
}
示例2: convert
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@JRubyMethod(required = 1, optional = 2)
public IRubyObject convert(ThreadContext context, IRubyObject[] args) {
AbstractNode node = NodeConverter.createASTNode(args[0]);
Object ret = null;
if (args.length == 1) {
ret = delegate.convert(
node,
null,
Collections.emptyMap());
} else if (args.length == 2) {
ret = delegate.convert(
node,
(String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
Collections.emptyMap());//RubyString.objAsString(context, args[1]).asJavaString());
} else if (args.length == 3) {
ret = delegate.convert(
node,
(String) JavaEmbedUtils.rubyToJava(getRuntime(), args[1], String.class),
(Map) JavaEmbedUtils.rubyToJava(getRuntime(), args[2], Map.class));
}
return JavaEmbedUtils.javaToRuby(getRuntime(), ret);
}
示例3: toRubyObject
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private static IRubyObject toRubyObject(Ruby rubyRuntime, Object value) {
if (value instanceof List) {
return toRubyArray(rubyRuntime, (List<Object>) value);
} else {
if (isNotARubySymbol(value)) {
String stringValue = ((String) value);
if (stringValue.startsWith(":")) {
return RubyUtils.toSymbol(rubyRuntime, stringValue.substring(1));
}
}
IRubyObject iRubyObject = JavaEmbedUtils.javaToRuby(rubyRuntime, value);
return iRubyObject;
}
}
示例4: defineVariable
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private void defineVariable(String variable, Object value) {
try {
GlobalVariable v = new GlobalVariable(interpreter, "$" + variable, JavaEmbedUtils.javaToRuby(interpreter, value));
interpreter.defineVariable(v, Scope.GLOBAL);
} catch (Throwable t) {
throw new ScriptException("Failed to define variable " + variable + " value = " + value + ":" + t.getMessage(), t);
}
}
示例5: convertToRuby
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private IRubyObject[] convertToRuby(Object[] javaArgs) {
if (javaArgs == null || javaArgs.length == 0) {
return new IRubyObject[0];
}
IRubyObject[] rubyArgs = new IRubyObject[javaArgs.length];
for (int i = 0; i < javaArgs.length; ++i) {
rubyArgs[i] = JavaEmbedUtils.javaToRuby(this.ruby, javaArgs[i]);
}
return rubyArgs;
}
示例6: invokeMethod
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
@Override
public Object invokeMethod(Object target, String name, Object... args) {
try {
IRubyObject rubyObject = JavaEmbedUtils.javaToRuby(container.getProvider().getRuntime(), target);
return container.callMethod(rubyObject, name, args);
} catch (Throwable e) {
throw SpongeUtils.wrapException(target + "." + name, e);
}
}
示例7: doCompile
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public JRubyCompiledScript doCompile(Script script) throws ScriptCompilationException {
Ruby runtime = JavaEmbedUtils.initialize(new ArrayList());
IRubyObject rubyScript = JavaEmbedUtils.javaToRuby(runtime, script.getScriptAsString());
try {
Node node = runtime.parse(rubyScript.asSymbol(), "<unknown>", null, 0);
return new JRubyCompiledScript(runtime, node);
} catch (Exception e) {
throw new ScriptExecutionException("Failed to execute script [" + script.getName() + "]", e);
}
}
示例8: get
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public IRubyObject get(String name) {
String modifiedName = name.substring(1);
Object obj = parameters.get(modifiedName);
if (obj instanceof IAccessor) {
return ((IAccessor) obj).getValue();
} else {
return JavaEmbedUtils.javaToRuby(runtime, obj);
}
}
示例9: TableImpl
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public TableImpl(Table delegate, Ruby rubyRuntime) {
super(delegate, rubyRuntime);
this.delegate = delegate;
IRubyObject rubyTable = JavaEmbedUtils.javaToRuby(rubyRuntime, delegate);
rows = new RowsImpl(
RubyUtils.rubyToJava(rubyRuntime, rubyTable.getInstanceVariables().getInstanceVariable("@rows"), Rows.class),
rubyRuntime);
}
示例10: toRubyObject
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
public IRubyObject toRubyObject(Object object) {
return JavaEmbedUtils.javaToRuby(ruby.getProvider().getRuntime(), object);
}
示例11: toRubyObject
import org.jruby.javasupport.JavaEmbedUtils; //导入方法依赖的package包/类
private IRubyObject toRubyObject(Object javaObject)
{
return JavaEmbedUtils.javaToRuby(runtime, javaObject);
}