How do you use jdk.jshell.CompletenessAnalyzer
? this class is not public !
I want to implement my own shell with jshell with my own custom commands like /bin/bash .
how can implement auto completion ?
jshell support double tab for auto completion , but i can not understand how can implement for my own commands .
this is my example code :
import jdk.jshell.JShell;
import java.util.Scanner;
public class App {
private static JShell jshell;
public static void main(String[] args) {
jshell = JShell.create();
System.out.println("Custom Shell");
System.out.println("Type '/exit' to exit the shell");
Scanner scanner = new Scanner(System.in);
String userInput;
do {
System.out.print("> ");
userInput = scanner.nextLine();
if (!userInput.equals("/exit")) {
executeCommand(userInput);
}
} while (!userInput.equals("/exit"));
jshell.close();
scanner.close();
}
private static void executeCommand(String command) {
jshell.eval(command).forEach(System.out::println);
}
}
Note : i won't to use jline .
I have just been reading up on the JShell API, and while searching, I came across this question.
It looks like your
executeCommand()
method prints and then discards the result of callingjshell.eval()
.For a more sophisticated shell, you could call
jshell.sourceCodeAnalysis()
, to get aSourceCodeAnalysis
object, which you can then use to analyze your input string to see if it is complete, or even to check for suggestions on how to complete it.I haven't tried it yet, but what I expect to do is as follwos:
SourceCodeAnalysis
object to parse the string into a list of snippetsJShell
objectErroneousSnippet
s