Skip to content

Commit 23394b3

Browse files
committed
Document behaviour of compile and eval methods
When a valid filename is specified by the ScriptEngine.FILENAME key in the engine scope bindings, the given script will be ignored and the file described by the filename will be compiled (and run) instead. Signed-off-by: Squareys <Squareys@googlemail.com>
1 parent c2a33d3 commit 23394b3

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/main/java/org/scijava/plugins/scripting/java/JavaEngine.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ public class JavaEngine extends AbstractScriptEngine {
118118
private JavaService javaService;
119119

120120
/**
121-
* Compiles and runs the specified {@code .java} class.
121+
* Compiles and runs the specified {@code .java} class. If a filename is set
122+
* in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
123+
* this method compiles that file and runs the resulting main class instead.
122124
* <p>
123125
* The currently active {@link JavaService} is responsible for running the
124126
* class.
@@ -149,7 +151,9 @@ public Object eval(String script) throws ScriptException {
149151
}
150152

151153
/**
152-
* Compiles and runs the specified {@code .java} class.
154+
* Compiles and runs the specified {@code .java} class. If a filename is set
155+
* in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
156+
* this method compiles that file and runs the resulting main class instead.
153157
* <p>
154158
* The currently active {@link JavaService} is responsible for running the
155159
* class.
@@ -171,12 +175,16 @@ public Object eval(Reader reader) throws ScriptException {
171175
}
172176

173177
/**
174-
* Compiles and runs the specified {@code .java} class.
178+
* Compiles and runs the specified {@code .java} class. If a filename is set
179+
* in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
180+
* this method compiles that file and returns its resulting main class
181+
* instead.
175182
*
176183
* @param script the source code for a Java class
177184
* @return the compiled Java class as {@link Class}.
178185
*/
179186
public Class<?> compile(String script) throws ScriptException {
187+
// get filename from engine scope bindings
180188
final String path = (String) get(FILENAME);
181189
File file = path == null ? null : new File(path);
182190

@@ -244,7 +252,10 @@ public Class<?> compile(String script) throws ScriptException {
244252
}
245253

246254
/**
247-
* Compiles and runs the specified {@code .java} class.
255+
* Compiles and runs the specified {@code .java} class. If a filename is set
256+
* in the engine scope bindings via the {@link ScriptEngine#FILENAME} key,
257+
* this method compiles that file and returns its resulting main class
258+
* instead.
248259
*
249260
* @param reader the reader producing the source code for a Java class
250261
* @return the compiled Java class as {@link Class}.

0 commit comments

Comments
 (0)