59 import jdk.jshell.TaskFactory.CompileTask; |
59 import jdk.jshell.TaskFactory.CompileTask; |
60 import jdk.jshell.TaskFactory.ParseTask; |
60 import jdk.jshell.TaskFactory.ParseTask; |
61 import jdk.jshell.TreeDissector.ExpressionInfo; |
61 import jdk.jshell.TreeDissector.ExpressionInfo; |
62 import jdk.jshell.Wrap.Range; |
62 import jdk.jshell.Wrap.Range; |
63 import jdk.jshell.Snippet.Status; |
63 import jdk.jshell.Snippet.Status; |
|
64 import jdk.jshell.spi.ExecutionControl.ClassBytecodes; |
|
65 import jdk.jshell.spi.ExecutionControl.ClassInstallException; |
|
66 import jdk.jshell.spi.ExecutionControl.EngineTerminationException; |
|
67 import jdk.jshell.spi.ExecutionControl.InternalException; |
|
68 import jdk.jshell.spi.ExecutionControl.NotImplementedException; |
|
69 import jdk.jshell.spi.ExecutionControl.ResolutionException; |
|
70 import jdk.jshell.spi.ExecutionControl.RunException; |
|
71 import jdk.jshell.spi.ExecutionControl.UserException; |
64 import static java.util.stream.Collectors.toList; |
72 import static java.util.stream.Collectors.toList; |
65 import static java.util.stream.Collectors.toSet; |
73 import static java.util.stream.Collectors.toSet; |
66 import static java.util.Collections.singletonList; |
74 import static java.util.Collections.singletonList; |
67 import static jdk.internal.jshell.debug.InternalDebugControl.DBG_GEN; |
75 import static jdk.internal.jshell.debug.InternalDebugControl.DBG_GEN; |
68 import static jdk.jshell.Util.DOIT_METHOD_NAME; |
76 import static jdk.jshell.Util.DOIT_METHOD_NAME; |
539 String value = null; |
547 String value = null; |
540 JShellException exception = null; |
548 JShellException exception = null; |
541 if (si.status().isDefined()) { |
549 if (si.status().isDefined()) { |
542 if (si.isExecutable()) { |
550 if (si.isExecutable()) { |
543 try { |
551 try { |
544 value = state.executionControl().invoke(si.classFullName(), DOIT_METHOD_NAME); |
552 value = state.executionControl().invoke(si.classFullName(), DOIT_METHOD_NAME); |
545 value = si.subKind().hasValue() |
553 value = si.subKind().hasValue() |
546 ? expunge(value) |
554 ? expunge(value) |
547 : ""; |
555 : ""; |
548 } catch (EvalException ex) { |
556 } catch (ResolutionException ex) { |
|
557 DeclarationSnippet sn = (DeclarationSnippet) state.maps.getSnippetDeadOrAlive(ex.id()); |
|
558 exception = new UnresolvedReferenceException(sn, ex.getStackTrace()); |
|
559 } catch (UserException ex) { |
549 exception = translateExecutionException(ex); |
560 exception = translateExecutionException(ex); |
550 } catch (JShellException ex) { |
561 } catch (RunException ex) { |
551 // UnresolvedReferenceException |
562 // StopException - no-op |
552 exception = ex; |
563 } catch (InternalException ex) { |
|
564 state.debug(ex, "invoke"); |
|
565 } catch (EngineTerminationException ex) { |
|
566 state.closeDown(); |
553 } |
567 } |
554 } else if (si.subKind() == SubKind.VAR_DECLARATION_SUBKIND) { |
568 } else if (si.subKind() == SubKind.VAR_DECLARATION_SUBKIND) { |
555 switch (((VarSnippet) si).typeName()) { |
569 switch (((VarSnippet) si).typeName()) { |
556 case "byte": |
570 case "byte": |
557 case "short": |
571 case "short": |
698 } |
712 } |
699 } |
713 } |
700 |
714 |
701 /** |
715 /** |
702 * If there are classes to load, loads by calling the execution engine. |
716 * If there are classes to load, loads by calling the execution engine. |
703 * @param classnames names of the classes to load. |
717 * @param classbytecoes names of the classes to load. |
704 */ |
718 */ |
705 private void load(Collection<String> classnames) { |
719 private void load(Collection<ClassBytecodes> classbytecoes) { |
706 if (!classnames.isEmpty()) { |
720 if (!classbytecoes.isEmpty()) { |
707 state.executionControl().load(classnames); |
721 ClassBytecodes[] cbcs = classbytecoes.toArray(new ClassBytecodes[classbytecoes.size()]); |
708 } |
722 try { |
709 } |
723 state.executionControl().load(cbcs); |
710 |
724 state.classTracker.markLoaded(cbcs); |
711 private EvalException translateExecutionException(EvalException ex) { |
725 } catch (ClassInstallException ex) { |
|
726 state.classTracker.markLoaded(cbcs, ex.installed()); |
|
727 } catch (NotImplementedException ex) { |
|
728 state.debug(ex, "Seriously?!? load not implemented"); |
|
729 } catch (EngineTerminationException ex) { |
|
730 state.closeDown(); |
|
731 } |
|
732 } |
|
733 } |
|
734 |
|
735 private EvalException translateExecutionException(UserException ex) { |
712 StackTraceElement[] raw = ex.getStackTrace(); |
736 StackTraceElement[] raw = ex.getStackTrace(); |
713 int last = raw.length; |
737 int last = raw.length; |
714 do { |
738 do { |
715 if (last == 0) { |
739 if (last == 0) { |
716 last = raw.length - 1; |
740 last = raw.length - 1; |
737 } |
761 } |
738 String msg = ex.getMessage(); |
762 String msg = ex.getMessage(); |
739 if (msg.equals("<none>")) { |
763 if (msg.equals("<none>")) { |
740 msg = null; |
764 msg = null; |
741 } |
765 } |
742 return new EvalException(msg, ex.getExceptionClassName(), elems); |
766 return new EvalException(msg, ex.causeExceptionClass(), elems); |
743 } |
767 } |
744 |
768 |
745 private boolean isWrap(StackTraceElement ste) { |
769 private boolean isWrap(StackTraceElement ste) { |
746 return PREFIX_PATTERN.matcher(ste.getClassName()).find(); |
770 return PREFIX_PATTERN.matcher(ste.getClassName()).find(); |
747 } |
771 } |