• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java JShell类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中jdk.jshell.JShell的典型用法代码示例。如果您正苦于以下问题:Java JShell类的具体用法?Java JShell怎么用?Java JShell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JShell类属于jdk.jshell包,在下文中一共展示了JShell类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: createJShellInstance

import jdk.jshell.JShell; //导入依赖的package包/类
@Override
protected JShell createJShellInstance() {
    ClassLoader ctxLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(Lookup.getDefault().lookup(ClassLoader.class));
        JShell.Builder b = makeBuilder();
        if (execGen != null) {
                b.executionEngine(new CaptureExecControl(execGen), Collections.emptyMap());
        }
        String s = System.getProperty("jshell.logging.properties");
        if (s != null) {
            b = b.remoteVMOptions(quote("-Djava.util.logging.config.file=" + s));
        }
        JShell ret = b.build();
        return ret;
    } finally {
        Thread.currentThread().setContextClassLoader(ctxLoader);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:JShellLauncher.java


示例2: attachTo

import jdk.jshell.JShell; //导入依赖的package包/类
private synchronized void attachTo(JShell shell) {
    if (shell == state) {
        return;
    }
    if (state != null) {
        sub.unsubscribe();
        state = null;
    }
    if (shell != null) {
        NR subscription = new NR(this, shell);
        subscription.subscribe();
        // may fail in JShell, record in member variables only after successful
        // registration
        state = shell;
        sub = subscription;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:SnippetNodes.java


示例3: customizeJShell

import jdk.jshell.JShell; //导入依赖的package包/类
public JShell.Builder customizeJShell(JShell.Builder b) {
    if (ShellProjectUtils.isModularProject(project)) {
        if (requiredModules != null) {
            b.compilerOptions("--add-modules", String.join(",", requiredModules)); // NOI18N
            
        }
        // extra options to include the modules:
        List<String> opts = ShellProjectUtils.launchVMOptions(project);
        b.remoteVMOptions(opts.toArray(new String[opts.size()]));
        
        String modPath = addRoots("", ShellProjectUtils.projectRuntimeModulePath(project));
        if (!modPath.isEmpty()) {
            b.remoteVMOptions("--module-path", modPath);
        }
    }
    return b;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:JShellEnvironment.java


示例4: getSnippets

import jdk.jshell.JShell; //导入依赖的package包/类
/**
 * Returns the user-entered snippets. Does not return snippets, which are run
 * during the initial startup of JShell, just snippets executed afterwards.
 * 
 * @param onlyValid
 * @return 
 */
public List<Snippet> getSnippets(boolean onlyUser, boolean onlyValid) {
    Set<Snippet> initial = this.initialSetupSnippets;
    JShell sh = shell;
    if (sh == null) {
        return Collections.emptyList();
    }
    
    List<Snippet> snips = new ArrayList<>(sh.snippets().collect(Collectors.toList()));
    if (onlyUser) {
        snips.removeAll(initial);
        snips.removeAll(excludedSnippets);
    }
    if (onlyValid) {
        for (Iterator<Snippet> it = snips.iterator(); it.hasNext(); ) {
            Snippet s = it.next();
            if (!validSnippet(s)) {
                it.remove();
            }
        }
    }
    return snips;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ShellSession.java


示例5: testTempNameGenerator

import jdk.jshell.JShell; //导入依赖的package包/类
public void testTempNameGenerator() {
    JShell.Builder builder = getBuilder().tempVariableNameGenerator(new Supplier<String>() {
        int count = 0;

        @Override
        public String get() {
            return "temp" + ++count;
        }
    });
    try (JShell jShell = builder.build()) {
        for (int i = 0; i < 3; ++i) {
            VarSnippet v = (VarSnippet) jShell.eval("2 + " + (i + 1)).get(0).snippet();
            assertEquals("temp" + (i + 1), v.name(), "Custom id: ");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:17,代码来源:IdGeneratorTest.java


示例6: build

import jdk.jshell.JShell; //导入依赖的package包/类
public CodeEvaluator build() {
    JShell.Builder builder = JShell.builder();
    if (this.out != null) builder.out(this.out);
    if (this.err != null) builder.err(this.err);

    JShell shell = builder
            .remoteVMOptions(this.vmOpts.toArray(new String[this.vmOpts.size()]))
            .compilerOptions(this.compilerOpts.toArray(new String[this.compilerOpts.size()]))
            .build();

    for (String cp : this.classpath)
        shell.addToClasspath(cp);

    if (timeout > 0L) {
        return new CodeEvaluatorWithTimeout(shell, this.startupScripts, this.timeout, this.timeoutUnit);
    } else {
        return new CodeEvaluator(shell, this.startupScripts);
    }
}
 
开发者ID:SpencerPark,项目名称:IJava,代码行数:20,代码来源:CodeEvaluatorBuilder.java


示例7: start

import jdk.jshell.JShell; //导入依赖的package包/类
@Override
public void start(Stage primaryStage) throws Exception {

    JShell shell = JShell.builder().build();

    TextField textField = new TextField();
    Button evalButton = new Button("eval");
    ListView<String> listView = new ListView<>();

    evalButton.setOnAction(e -> {
        List<SnippetEvent> events = shell.eval(textField.getText());
        events.stream().map(event -> convert(event)).filter(s -> s != null).forEach(s -> listView.getItems().add(s));
    });

    BorderPane pane = new BorderPane();
    pane.setTop(new HBox(textField, evalButton));
    pane.setCenter(listView);
    Scene scene = new Scene(pane);
    primaryStage.setScene(scene);
    primaryStage.show();

}
 
开发者ID:AdoptOpenJDK,项目名称:jdk9-jigsaw,代码行数:23,代码来源:ShellFX.java


示例8: jshell

import jdk.jshell.JShell; //导入依赖的package包/类
private void jshell(@NotNull JShell shell, @NotNull String s, boolean showLog) throws JShellException {

        if (showLog) {
            log.info("$ {}", s);
        }

        List<SnippetEvent> eval = shell.eval(s);

        if (showLog) {
            if (eval.isEmpty()) {
                log.info("> ");
            }
            for (SnippetEvent event : eval) {
                showResult(event);
            }
        }

    }
 
开发者ID:sillelien,项目名称:dollar,代码行数:19,代码来源:Java9ScriptingLanguage.java


示例9: main

import jdk.jshell.JShell; //导入依赖的package包/类
public static void main(String[] args) {
	JShell myShell = JShell.create();

	System.out.println("Welcome to JShell Java API Demo");
	System.out.println("Please Enter a Snippet. Enter EXIT to exit:");
	try(Scanner reader = new Scanner(System.in)){
		while(true){
			String snippet = reader.nextLine();
			if ( "EXIT".equals(snippet)){
				break;
			}
			List<SnippetEvent> events = myShell.eval(snippet);
			events.stream().forEach(se -> {
				System.out.print("Evaluation status: " + se.status());
				System.out.println(" Evaluation result: " + se.value());
			});
		}
	}
	System.out.println("Snippets processed: ");
	myShell.snippets().forEach(s -> {
		String msg = String.format("%s -> %s", s.kind(), s.source());
		System.out.println(msg);
	});

	System.out.println("Methods: ");
	myShell.methods().forEach(m -> System.out.println(m.name() + " " + m.signature()));

	System.out.println("Variables: ");
	myShell.variables().forEach(v -> System.out.println(v.typeName() + " " + v.name()));
	myShell.close();
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:32,代码来源:JshellJavaApiDemo.java


示例10: customizeJShell

import jdk.jshell.JShell; //导入依赖的package包/类
@Override
public JShell.Builder customizeJShell(JShell.Builder b) {
    b = super.customizeJShell(b);
    JavaPlatform pl = ShellProjectUtils.findPlatform(getProject());
    if (!ShellProjectUtils.isModularJDK(pl)) {
        return b;
    }
    List<String> addReads = new ArrayList<>();
    addReads.add("--add-reads:java.jshell=ALL-UNNAMED");
    return b.remoteVMOptions(addReads.toArray(new String[addReads.size()]));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:12,代码来源:ProjectShellEnv.java


示例11: resetState

import jdk.jshell.JShell; //导入依赖的package包/类
protected void resetState() {
    closeState();

    // Initialize tool id mapping
    mainNamespace = new NameSpace("main", "");
    startNamespace = new NameSpace("start", "s");
    errorNamespace = new NameSpace("error", "e");
    mapSnippet = new LinkedHashMap<>();
    currentNameSpace = startNamespace;

    // Reset the replayable history, saving the old for restore
    replayableHistoryPrevious = replayableHistory;
    replayableHistory = new ArrayList<>();

    state = createJShellInstance();
    shutdownSubscription = state.onShutdown((JShell deadState) -> {
        if (deadState == state) {
            hardmsg("jshell.msg.terminated");
            live = false;
        }
    });
    analysis = state.sourceCodeAnalysis();
    live = true;
    if (!feedbackInitialized) {
        // One time per run feedback initialization
        feedbackInitialized = true;
        initFeedback();
    }

    if (cmdlineClasspath != null) {
        state.addToClasspath(cmdlineClasspath);
    }

    startUpRun(startup);
    currentNameSpace = mainNamespace;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:JShellTool.java


示例12: makeBuilder

import jdk.jshell.JShell; //导入依赖的package包/类
protected JShell.Builder makeBuilder() {
    return JShell.builder()
            .in(userin)
            .out(userout)
            .err(usererr)
            .tempVariableNameGenerator(()-> "$" + currentNameSpace.tidNext())
            .idGenerator((sn, i) -> (currentNameSpace == startNamespace || state.status(sn).isActive())
                    ? currentNameSpace.tid(sn)
                    : errorNamespace.tid(sn))
            .remoteVMOptions(remoteVMOptions.stream().toArray(String[]::new))
            .compilerOptions(compilerOptions.stream().toArray(String[]::new));
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:JShellTool.java


示例13: closeState

import jdk.jshell.JShell; //导入依赖的package包/类
protected void closeState() {
    live = false;
    JShell oldState = state;
    if (oldState != null) {
        oldState.unsubscribe(shutdownSubscription); // No notification
        oldState.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:JShellTool.java


示例14: unsubscribe

import jdk.jshell.JShell; //导入依赖的package包/类
synchronized void unsubscribe() {
    JShell s = shellRef.get();
    if (sub == null || s == null) {
        return;
    }
    s.unsubscribe(sub);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:SnippetNodes.java


示例15: getJShell

import jdk.jshell.JShell; //导入依赖的package包/类
JShell getJShell() {
    assert evaluator.isRequestProcessorThread();
    if (shell == null) {
        initJShell();
    }
    return shell;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ShellSession.java


示例16: createJShellInstance

import jdk.jshell.JShell; //导入依赖的package包/类
@Override
protected JShell createJShellInstance() {
    JShell shell = super.createJShellInstance();
    try {
        setupJShellClasspath(shell);
    } catch (ExecutionControlException ex) {
        Exceptions.printStackTrace(ex);
    }
    synchronized (ShellSession.this) {
        snippetRegistry = new SnippetRegistry(
                shell, bridgeImpl, workRoot, editorWorkRoot, 
                snippetRegistry);
        // replace for fresh instance !
        JShell oldShell = ShellSession.this.shell;
        ShellSession.this.shell = shell;
        if (oldShell != null) {
            FORCE_CLOSE_RP.post(() -> {
                propSupport.firePropertyChange(PROP_ENGINE, oldShell, shell);
            });
        }
    }
    this.subscription = shell.onSnippetEvent(this);
    // it's possible that the shell's startup will terminate the session
    if (!detached) {
        shell.onShutdown(sh -> closedDelayed());
        ignoreClose = false;
    }
    return shell;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:ShellSession.java


示例17: stopExecutingCode

import jdk.jshell.JShell; //导入依赖的package包/类
public void stopExecutingCode() {
    JShell shell = this.shell;
    if (shell == null || !model.isExecute()) {
        return;
    }
    shell.stop();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:8,代码来源:ShellSession.java


示例18: SnippetRegistry

import jdk.jshell.JShell; //导入依赖的package包/类
public SnippetRegistry(JShell state, ShellAccessBridge shellExecutor, FileObject persistentRoot, FileObject transientRoot, 
        SnippetRegistry previousRegistry) {
    this.state = state;
    this.persistentSnippetsRoot = persistentRoot;
    this.transientSnippetsRoot = transientRoot;
    this.shellExecutor = shellExecutor;
    this.counter = previousRegistry == null ?  
            new AtomicInteger(0) :
            previousRegistry.counter;
    
    if (previousRegistry != null) {
        copyFrom(previousRegistry);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:SnippetRegistry.java


示例19: wrapInput

import jdk.jshell.JShell; //导入依赖的package包/类
/**
 * Generates a wrapping for a text without declaring a new Snippet
 * @param state JShell instance
 * @param input source text
 * @return wrapped source
 */
public static SnippetWrapping wrapInput(JShell state, String input) {
    if (input.trim().isEmpty()) {
        input = input + ";"; // NOI18N
    }
    List<SnippetWrapper> wraps = state.sourceCodeAnalysis().wrappers(input);
    if (wraps.size() != 1) {
        return null;
    }
    return new WrappedWrapper(null, wraps.get(0), state);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:JShellAccessor.java


示例20: isDebugEnabled

import jdk.jshell.JShell; //导入依赖的package包/类
/**
 * Tests if any of the specified debug flags are enabled.
 *
 * @param state the JShell instance
 * @param flag the {@code DBG_*} bits to check
 * @return true if any of the flags are enabled
 */
public static boolean isDebugEnabled(JShell state, int flag) {
    if (debugMap == null) {
        return false;
    }
    Integer flags = debugMap.get(state);
    if (flags == null) {
        return false;
    }
    return (flags & flag) != 0;
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:18,代码来源:InternalDebugControl.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java SchedulerRepository类代码示例发布时间:2022-05-22
下一篇:
Java ShimmerFrameLayout类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap