当前位置: 首页>>代码示例>>Java>>正文


Java Node类代码示例

本文整理汇总了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));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JRubyScriptUtils.java

示例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));
}
 
开发者ID:deathspeeder,项目名称:class-guard,代码行数:28,代码来源:JRubyScriptUtils.java

示例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();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:14,代码来源:JRubyScriptUtils.java

示例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);
    }
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:11,代码来源:JRubyLocalScriptExecutor.java

示例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);
    }
 
开发者ID:mikoto2000,项目名称:MiscellaneousStudy,代码行数:34,代码来源:StudyJRuby03.java

示例6: JRubyCompiledScript

import org.jruby.ast.Node; //导入依赖的package包/类
private JRubyCompiledScript(Ruby runtime, Node node) {
    this.runtime = runtime;
    this.node = node;
}
 
开发者ID:Gigaspaces,项目名称:xap-openspaces,代码行数:5,代码来源:JRubyLocalScriptExecutor.java

示例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);
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:6,代码来源:RubyUtil.java


注:本文中的org.jruby.ast.Node类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。