Skip to content

Commit 6b186e3

Browse files
ctruedendscho
authored andcommitted
ScriptInterpreter: remember the associated language
It simplifies things downstream to be able to query the associated ScriptLanguage later, since it is known at construction time anyway. This does *not* persist the most recently used interpreter language!
1 parent f998ed8 commit 6b186e3

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

src/main/java/org/scijava/script/DefaultScriptInterpreter.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,20 +42,21 @@
4242
*/
4343
public class DefaultScriptInterpreter implements ScriptInterpreter {
4444

45+
private final ScriptLanguage language;
4546
private final ScriptEngine engine;
4647
private final History history;
47-
private String currentCommand = "";
4848

4949
/**
5050
* Constructs a new {@link DefaultScriptInterpreter}.
5151
*
5252
* @param scriptService the script service
53-
* @param engine the script engine
53+
* @param language the script language
5454
*/
5555
public DefaultScriptInterpreter(final PrefService prefs,
56-
final ScriptService scriptService, final ScriptEngine engine)
56+
final ScriptService scriptService, final ScriptLanguage language)
5757
{
58-
this.engine = engine;
58+
this.language = language;
59+
engine = language.getScriptEngine();
5960
history = new History(prefs, engine.getClass().getName());
6061
readHistory();
6162
}
@@ -74,7 +75,6 @@ public synchronized void writeHistory() {
7475

7576
@Override
7677
public synchronized String walkHistory(final String currentCommand, boolean forward) {
77-
this.currentCommand = currentCommand;
7878
if (history == null) return currentCommand;
7979
history.replace(currentCommand);
8080
return forward ? history.next() : history.previous();
@@ -87,6 +87,11 @@ public void eval(String command) throws ScriptException {
8787
engine.eval(command);
8888
}
8989

90+
@Override
91+
public ScriptLanguage getLanguage() {
92+
return language;
93+
}
94+
9095
@Override
9196
public ScriptEngine getEngine() {
9297
return engine;

src/main/java/org/scijava/script/ScriptInterpreter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ public interface ScriptInterpreter {
6969
*/
7070
void eval(String command) throws ScriptException;
7171

72+
/**
73+
* Returns the associated {@link ScriptLanguage}.
74+
*/
75+
ScriptLanguage getLanguage();
76+
7277
/**
7378
* Returns the associated {@link ScriptEngine}.
7479
*

0 commit comments

Comments
 (0)