Search in sources :

Example 1 with SnippetEvent

use of jdk.jshell.SnippetEvent 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 2 with SnippetEvent

use of jdk.jshell.SnippetEvent 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 3 with SnippetEvent

use of jdk.jshell.SnippetEvent 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)

Example 4 with SnippetEvent

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

the class ShellService method eval.

public synchronized void eval(String command) {
    List<SnippetEvent> events = shell.eval(command);
    for (SnippetEvent event : events) {
        if (event.snippet() instanceof VarSnippet) {
            String type = ((VarSnippet) event.snippet()).typeName();
            String name = ((VarSnippet) event.snippet()).name();
            String value = event.value();
            VarData varData = new VarData(type, name, value);
            eventBus.publish(Topics.VAR_CREATED_TOPIC, varData);
            variables.add(varData);
        }
    }
}
Also used : VarSnippet(jdk.jshell.VarSnippet) SnippetEvent(jdk.jshell.SnippetEvent) VarData(com.guigarage.shell.event.VarData)

Example 5 with SnippetEvent

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

the class JShellSample5 method print.

public static void print(List<SnippetEvent> events) {
    for (SnippetEvent event : events) {
        if (event.snippet() instanceof VarSnippet) {
            String name = ((VarSnippet) event.snippet()).name();
            String id = ((VarSnippet) event.snippet()).id();
            System.out.println("Variable " + name + " defined with ID " + id);
        }
    }
}
Also used : VarSnippet(jdk.jshell.VarSnippet) SnippetEvent(jdk.jshell.SnippetEvent)

Aggregations

SnippetEvent (jdk.jshell.SnippetEvent)5 JShell (jdk.jshell.JShell)3 VarSnippet (jdk.jshell.VarSnippet)3 VarData (com.guigarage.shell.event.VarData)1 List (java.util.List)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