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()));
}
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()));
}
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();
}
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);
}
}
}
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);
}
}
}
Aggregations