@@ -20,6 +20,7 @@ public class CodeEvaluator {
2020 private static final Pattern LAST_LINE = Pattern .compile ("(?:^|\r ?\n )(?<last>.*)$" );
2121
2222 private static final String NO_MAGIC_RETURN = "\" __NO_MAGIC_RETURN\" " ;
23+ private static final String INDENTATION = " " ;
2324
2425 private static final Method SNIPPET_CLASS_NAME_METHOD ;
2526
@@ -32,33 +33,32 @@ public class CodeEvaluator {
3233 }
3334 }
3435
35- private static final String INDENTATION = " " ;
3636
37- private final JShell shell ;
37+ private final String name ;
3838 private final JJavaExecutionControlProvider execControlProvider ;
3939 private final String execControlID ;
40- private final SourceCodeAnalysis sourceAnalyzer ;
4140
4241 public CodeEvaluator (
43- JShell shell ,
42+ String name ,
4443 JJavaExecutionControlProvider execControlProvider ,
4544 String execControlID ) {
4645
47- this .shell = shell ;
46+ this .name = name ;
4847 this .execControlProvider = execControlProvider ;
4948 this .execControlID = execControlID ;
50- this .sourceAnalyzer = shell .sourceCodeAnalysis ();
5149 }
5250
53- public Object eval (String code , EvalTimer timer ) {
51+ public Object eval (JShell shell , String code , EvalTimer timer ) {
52+
53+ SourceCodeAnalysis sca = shell .sourceCodeAnalysis ();
5454
5555 Object lastResult = null ;
56- SourceCodeAnalysis .CompletionInfo info = this . sourceAnalyzer .analyzeCompletion (code );
56+ SourceCodeAnalysis .CompletionInfo info = sca .analyzeCompletion (code );
5757
5858 while (info .completeness ().isComplete ()) {
5959
60- lastResult = evalSingle (info .source (), timer );
61- info = sourceAnalyzer .analyzeCompletion (info .remaining ());
60+ lastResult = evalSingle (shell , info .source (), timer );
61+ info = sca .analyzeCompletion (info .remaining ());
6262 }
6363
6464 if (info .completeness () != SourceCodeAnalysis .Completeness .EMPTY ) {
@@ -68,7 +68,7 @@ public Object eval(String code, EvalTimer timer) {
6868 return lastResult ;
6969 }
7070
71- protected Object evalSingle (String code , EvalTimer timer ) {
71+ protected Object evalSingle (JShell shell , String code , EvalTimer timer ) {
7272
7373 JJavaExecutionControl execControl = execControlProvider .getRegisteredControlByID (execControlID );
7474 List <SnippetEvent > events = timer .runAndMeasureStep (() -> shell .eval (code ));
@@ -80,7 +80,7 @@ protected Object evalSingle(String code, EvalTimer timer) {
8080 for (SnippetEvent event : events ) {
8181 if (event .status () == Snippet .Status .OVERWRITTEN ) {
8282 // if a new snippet changed some other definition, drop the older one
83- dropSnippet (event .snippet ());
83+ dropSnippet (shell , event .snippet ());
8484 continue ;
8585 }
8686
@@ -146,7 +146,7 @@ protected Object evalSingle(String code, EvalTimer timer) {
146146 /**
147147 * Try to clean up information linked to a code snippet and the snippet itself
148148 */
149- private void dropSnippet (Snippet snippet ) {
149+ private void dropSnippet (JShell shell , Snippet snippet ) {
150150 JJavaExecutionControl execControl = execControlProvider .getRegisteredControlByID (execControlID );
151151 shell .drop (snippet );
152152 // snippet.classFullName() returns name of a wrapper class created for a snippet
@@ -211,8 +211,8 @@ private String computeIndentation(String partialStatement) {
211211 : currentIndentation ;
212212 }
213213
214- public String isComplete (String code ) {
215- SourceCodeAnalysis .CompletionInfo info = this . sourceAnalyzer .analyzeCompletion (code );
214+ public String isComplete (SourceCodeAnalysis sourceAnalyzer , String code ) {
215+ SourceCodeAnalysis .CompletionInfo info = sourceAnalyzer .analyzeCompletion (code );
216216 while (info .completeness ().isComplete ()) {
217217 info = sourceAnalyzer .analyzeCompletion (info .remaining ());
218218 }
@@ -228,7 +228,7 @@ public String isComplete(String code) {
228228 case CONSIDERED_INCOMPLETE :
229229 case DEFINITELY_INCOMPLETE :
230230 // Compute the indent of the last line and match it
231- return this . computeIndentation (info .remaining ());
231+ return computeIndentation (info .remaining ());
232232 default :
233233 // For completeness, return an "I don't know" if we somehow get down here
234234 return BaseKernel .IS_COMPLETE_MAYBE ;
0 commit comments