本文整理汇总了Java中org.jruby.ast.Node类的典型用法代码示例。如果您正苦于以下问题:Java Node类的具体用法?Java Node怎么用?Java Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Node类属于org.jruby.ast包,在下文中一共展示了Node类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createJRubyObject
import org.jruby.ast.Node; //导入依赖的package包/类
/**
* Create a new JRuby-scripted object from the given script source.
* @param scriptSource the script source text
* @param interfaces the interfaces that the scripted Java object is to implement
* @param classLoader the {@link ClassLoader} to create the script proxy with
* @return the scripted Java object
* @throws JumpException in case of JRuby parsing failure
*/
public static Object createJRubyObject(String scriptSource, Class<?>[] interfaces, ClassLoader classLoader) {
Ruby ruby = initializeRuntime();
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
IRubyObject rubyObject = ruby.runNormally(scriptRootNode);
if (rubyObject instanceof RubyNil) {
String className = findClassName(scriptRootNode);
rubyObject = ruby.evalScriptlet("\n" + className + ".new");
}
// still null?
if (rubyObject instanceof RubyNil) {
throw new IllegalStateException("Compilation of JRuby script returned RubyNil: " + rubyObject);
}
return Proxy.newProxyInstance(classLoader, interfaces, new RubyObjectInvocationHandler(rubyObject, ruby));
}
示例2: createJRubyObject
import org.jruby.ast.Node; //导入依赖的package包/类
/**
* Create a new JRuby-scripted object from the given script source.
* @param scriptSource the script source text
* @param interfaces the interfaces that the scripted Java object is to implement
* @param classLoader the {@link ClassLoader} to create the script proxy with
* @return the scripted Java object
* @throws JumpException in case of JRuby parsing failure
*/
@SuppressWarnings("deprecation")
public static Object createJRubyObject(String scriptSource, Class<?>[] interfaces, ClassLoader classLoader) {
Ruby ruby = initializeRuntime();
Node scriptRootNode = ruby.parseEval(scriptSource, "", null, 0);
// Keep using the deprecated runNormally variant for JRuby 1.1/1.2 compatibility...
IRubyObject rubyObject = ruby.runNormally(scriptRootNode, false);
if (rubyObject instanceof RubyNil) {
String className = findClassName(scriptRootNode);
rubyObject = ruby.evalScriptlet("\n" + className + ".new");
}
// still null?
if (rubyObject instanceof RubyNil) {
throw new IllegalStateException("Compilation of JRuby script returned RubyNil: " + rubyObject);
}
return Proxy.newProxyInstance(classLoader, interfaces, new RubyObjectInvocationHandler(rubyObject, ruby));
}
示例3: findClassName
import org.jruby.ast.Node; //导入依赖的package包/类
/**
* Given the root {@link Node} in a JRuby AST will locate the name of the
* class defined by that AST.
* @throws IllegalArgumentException if no class is defined by the supplied AST
*/
private static String findClassName(Node rootNode) {
ClassNode classNode = findClassNode(rootNode);
if (classNode == null) {
throw new IllegalArgumentException("Unable to determine class name for root node '" + rootNode + "'");
}
Colon2Node node = (Colon2Node) classNode.getCPath();
return node.getName();
}
示例4: doCompile
import org.jruby.ast.Node; //导入依赖的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);
}
}
示例5: main
import org.jruby.ast.Node; //导入依赖的package包/类
public static void main(String[] args) throws IOException {
final String scriptPath = args[0];
final String gemsPath = args[1];
final Path basePath = Paths.get(gemsPath);
final List<String> loadPaths = new ArrayList<>();
Files.walkFileTree(basePath, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path file, BasicFileAttributes attrs) throws IOException {
String fileStr = file.toString();
if (fileStr.endsWith("lib")) {
loadPaths.add(fileStr);
return FileVisitResult.SKIP_SUBTREE;
}
return FileVisitResult.CONTINUE;
}
});
RubyInstanceConfig config = new RubyInstanceConfig();
config.setLoadPaths(loadPaths);
Ruby ruby = Ruby.newInstance(config);
Path p = Paths.get(scriptPath);
Node node = ruby.parseFile(
Files.newInputStream(p),
p.toString(),
ruby.getCurrentContext().getCurrentScope(),
0);
IRubyObject obj = ruby.runNormally(node);
}
示例6: JRubyCompiledScript
import org.jruby.ast.Node; //导入依赖的package包/类
private JRubyCompiledScript(Ruby runtime, Node node) {
this.runtime = runtime;
this.node = node;
}
示例7: evalScriptlet
import org.jruby.ast.Node; //导入依赖的package包/类
public static IRubyObject evalScriptlet(InputStream scriptStream) {
Ruby ruby = Ruby.newInstance();
Node scriptNode = ruby.parseFromMain(scriptStream, "test.rb");
return ruby.runInterpreter(scriptNode);
}