Search in sources :

Example 1 with JShell

use of jdk.jshell.JShell in project jdk9-jigsaw by AdoptOpenJDK.

the class JShellSample1 method main.

public static void main(String[] args) {
    JShell shell = JShell.builder().idGenerator((snippet, integer) -> "MyID" + integer).build();
    shell.eval("int a = 100;");
    shell.eval("100 + 100;");
    shell.variables().forEach(v -> System.out.println(v.typeName() + " " + v.name() + " " + v.id()));
}
Also used : JShell(jdk.jshell.JShell) Snippet(jdk.jshell.Snippet) JShell(jdk.jshell.JShell)

Example 2 with JShell

use of jdk.jshell.JShell in project jdk9-jigsaw by AdoptOpenJDK.

the class JShellSample3 method main.

public static void main(String[] args) {
    JShell shell = JShell.builder().build();
    List<SnippetEvent> events = shell.eval("void helloJShell() { System.out.println(\"hello VJUG\"); }");
    events.stream().forEach(e -> System.out.println(e.toString()));
}
Also used : SnippetEvent(jdk.jshell.SnippetEvent) JShell(jdk.jshell.JShell)

Example 3 with JShell

use of jdk.jshell.JShell in project jdk9-jigsaw by AdoptOpenJDK.

the class JShellSample4 method main.

public static void main(String[] args) {
    JShell shell = JShell.builder().build();
    List<SnippetEvent> events = shell.eval("int i = 100;");
    events.stream().forEach(e -> System.out.println(e.toString()));
}
Also used : SnippetEvent(jdk.jshell.SnippetEvent) JShell(jdk.jshell.JShell)

Example 4 with JShell

use of jdk.jshell.JShell in project jdk9-jigsaw by AdoptOpenJDK.

the class JShellSample5 method main.

public static void main(String[] args) throws Exception {
    JShell shell = JShell.builder().idGenerator((snippet, integer) -> "My ID " + integer).out(new PrintStream(new FileOutputStream("out.log"), true, "UTF-8")).err(new PrintStream(new FileOutputStream("error.log"), true, "UTF-8")).build();
    print(shell.eval("int a = 50;"));
}
Also used : PrintStream(java.io.PrintStream) List(java.util.List) VarSnippet(jdk.jshell.VarSnippet) JShell(jdk.jshell.JShell) Charset(java.nio.charset.Charset) Files(java.nio.file.Files) Paths(java.nio.file.Paths) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) SnippetEvent(jdk.jshell.SnippetEvent) PrintStream(java.io.PrintStream) FileOutputStream(java.io.FileOutputStream) JShell(jdk.jshell.JShell)

Example 5 with JShell

use of jdk.jshell.JShell in project jdk9-jigsaw by AdoptOpenJDK.

the class ShellFX method start.

@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();
}
Also used : Application(javafx.application.Application) Button(javafx.scene.control.Button) Scene(javafx.scene.Scene) HBox(javafx.scene.layout.HBox) TextField(javafx.scene.control.TextField) List(java.util.List) ListView(javafx.scene.control.ListView) VarSnippet(jdk.jshell.VarSnippet) Stage(javafx.stage.Stage) JShell(jdk.jshell.JShell) BorderPane(javafx.scene.layout.BorderPane) SnippetEvent(jdk.jshell.SnippetEvent) SnippetEvent(jdk.jshell.SnippetEvent) BorderPane(javafx.scene.layout.BorderPane) HBox(javafx.scene.layout.HBox) ListView(javafx.scene.control.ListView) Button(javafx.scene.control.Button) TextField(javafx.scene.control.TextField) Scene(javafx.scene.Scene) JShell(jdk.jshell.JShell)

Aggregations

JShell (jdk.jshell.JShell)7 SnippetEvent (jdk.jshell.SnippetEvent)4 List (java.util.List)2 VarSnippet (jdk.jshell.VarSnippet)2 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Charset (java.nio.charset.Charset)1 Files (java.nio.file.Files)1 Paths (java.nio.file.Paths)1 Application (javafx.application.Application)1 Scene (javafx.scene.Scene)1 Button (javafx.scene.control.Button)1 ListView (javafx.scene.control.ListView)1 TextField (javafx.scene.control.TextField)1 BorderPane (javafx.scene.layout.BorderPane)1 HBox (javafx.scene.layout.HBox)1 Stage (javafx.stage.Stage)1 Snippet (jdk.jshell.Snippet)1