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


Java JShell类代码示例

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


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


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