Skip to content

Commit

Permalink
[Feature/JShell] Replaced if elses with a switch thanks to java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
Alathreon committed Feb 20, 2024
1 parent 719cd75 commit 466b950
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ class RendererUtils {
private RendererUtils() {}

static String abortionCauseToString(JShellEvalAbortionCause abortionCause) {
if (abortionCause instanceof JShellEvalAbortionCause.TimeoutAbortionCause) {
return "Allowed time exceeded.";
} else if (abortionCause instanceof JShellEvalAbortionCause.UnhandledExceptionAbortionCause c) {
return "Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
} else if (abortionCause instanceof JShellEvalAbortionCause.CompileTimeErrorAbortionCause c) {
return "The code doesn't compile:\n" + String.join("\n", c.errors());
} else if (abortionCause instanceof JShellEvalAbortionCause.SyntaxErrorAbortionCause) {
return "The code doesn't compile, there are syntax errors in this code.";
}
throw new AssertionError();
return switch (abortionCause) {
case JShellEvalAbortionCause.TimeoutAbortionCause ignored -> "Allowed time exceeded.";
case JShellEvalAbortionCause.UnhandledExceptionAbortionCause c -> "Uncaught exception:\n" + c.exceptionClass() + ":" + c.exceptionMessage();
case JShellEvalAbortionCause.CompileTimeErrorAbortionCause c -> "The code doesn't compile:\n" + String.join("\n", c.errors());
case JShellEvalAbortionCause.SyntaxErrorAbortionCause ignored -> "The code doesn't compile, there are syntax errors in this code.";
};
}

enum GeneralStatus {
Expand Down

0 comments on commit 466b950

Please sign in to comment.