@@ -198,41 +198,33 @@ public void display(DisplayData data) {
198198 }
199199
200200 /**
201- * Same as {@link #eval (String)}, but not applying the renderer to evaluation result .
201+ * @deprecated unused, replaced with {@link #evalBuilder (String)} pipeline .
202202 */
203- public abstract Object evalRaw (String source );
203+ @ Deprecated (forRemoval = true )
204+ public DisplayData eval (String source ) {
205+ return evalBuilder (source ).resolveMagics ().renderResults ().eval ();
206+ }
204207
205208 /**
206- * Evaluates a code expression in the kernel's language environment and returns the result
207- * as display data. This is the core evaluation method called when executing code cells
208- * in a Jupyter notebook.
209- *
210- * <p>The implementation should:
211- * <ul>
212- * <li>Parse and evaluate the provided expression string</li>
213- * <li>Convert the evaluation result into appropriate display data formats</li>
214- * <li>Handle any language-specific evaluation context/scope</li>
215- * </ul>
216- *
217- * <p>The returned {@link DisplayData} can contain multiple representations of the result
218- * (e.g. text/plain, text/html, image/png) to allow rich display in the notebook.
219- * Return null if the expression produces no displayable result.
220- *
221- * @param expr The code expression to evaluate as received from the Jupyter frontend
222- * @return A {@link DisplayData} object containing the evaluation result in one or more
223- * MIME formats, or null if there is no displayable result
209+ * @deprecated unused, replaced with {@link #evalBuilder(String)} pipeline.
224210 */
225- public DisplayData eval (String expr ) {
226- Object result = evalRaw (expr );
227- if (result == null ) {
228- return null ;
229- }
211+ @ Deprecated (forRemoval = true )
212+ public Object evalRaw (String source ) {
213+ return evalBuilder (source ).resolveMagics ().eval ();
214+ }
230215
231- return result instanceof DisplayData
232- ? (DisplayData ) result
233- : getRenderer ().render (result );
216+ /**
217+ * Creates and returns a builder for an evaluation pipeline.
218+ */
219+ public <T > SimpleEvalBuilder <T > evalBuilder (String source ) {
220+ return new SimpleEvalBuilder <>(this , source );
234221 }
235222
223+ /**
224+ * Evaluates the source code in a way appropriate for a given kernel subclass.
225+ */
226+ protected abstract Object doEval (String source );
227+
236228 /**
237229 * Inspect the code to get things such as documentation for a function. This is
238230 * triggered by {@code shift-tab} in the Jupyter notebook which opens a tooltip displaying
@@ -360,21 +352,7 @@ public void interrupt() {
360352 // no-op
361353 }
362354
363- /**
364- * Formats an error into a human friendly format. The default implementation prints
365- * the stack trace as written by {@link Throwable#printStackTrace()} with a dividing
366- * separator as a prefix.
367- * <p>
368- * Subclasses may override this method write better messages for specific errors but
369- * may choose to still use this to display the stack trace. In this case it is recommended
370- * to add the output of this call to the end of the output list.
371- *
372- * @param e the error to format
373- * @return a list of lines that make up the formatted error. This format should
374- * not include strings with newlines but rather separate strings each to go on a
375- * new line.
376- */
377- public List <String > formatError (Throwable e ) {
355+ protected List <String > formatError (Throwable e ) {
378356 List <String > lines = new ArrayList <>();
379357 lines .add (this .errorStyler .secondary ("---------------------------------------------------------------------------" ));
380358
@@ -389,12 +367,6 @@ public List<String> formatError(Throwable e) {
389367 return lines ;
390368 }
391369
392- /*
393- * ===================================
394- * | Default handler implementations |
395- * ===================================
396- */
397-
398370 public void becomeHandlerForConnection (JupyterConnection connection ) {
399371 connection .setHandler (MessageType .EXECUTE_REQUEST , this ::handleExecuteRequest );
400372 connection .setHandler (MessageType .INSPECT_REQUEST , this ::handleInspectRequest );
@@ -446,7 +418,7 @@ protected synchronized void handleExecuteRequest(ShellReplyEnvironment env, Mess
446418 this .io .setJupyterInEnabled (request .isStdinEnabled ());
447419
448420 try {
449- DisplayData out = eval (request .getCode ());
421+ DisplayData out = evalBuilder (request .getCode ()). resolveMagics (). renderResults (). eval ( );
450422
451423 if (out != null ) {
452424 PublishExecuteResult result = new PublishExecuteResult (count , out );
0 commit comments