Skip to content

Commit 88775ec

Browse files
committed
ScriptService: getScript now creates the script
To avoid a proliferation of case logic and repeated creation code, ScriptService needs public API that retrieves a cached script and creates it if it doesn't exist. It is not necessary to have both a lookup-only and a lookup-and-create method: if an API consumer wants to check the existence of a ScriptInfo, the containing Collection is accessible. Thus getScript now simply creates the ScriptInfo if it does not already exist.
1 parent 5715522 commit 88775ec

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public Collection<ScriptInfo> getScripts() {
169169

170170
@Override
171171
public ScriptInfo getScript(final File scriptFile) {
172-
return scripts().get(scriptFile);
172+
return getOrCreate(scriptFile);
173173
}
174174

175175
@Override
@@ -455,7 +455,7 @@ private void addAliases(final HashMap<String, Class<?>> map,
455455
* are registered with the service.
456456
*/
457457
private ScriptInfo getOrCreate(final File file) {
458-
final ScriptInfo info = getScript(file);
458+
final ScriptInfo info = scripts().get(file);
459459
if (info != null) return info;
460460
return new ScriptInfo(getContext(), file);
461461
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ public interface ScriptService extends SingletonService<ScriptLanguage>,
117117
Collection<ScriptInfo> getScripts();
118118

119119
/**
120-
* Gets the {@link ScriptInfo} metadata for the script at the given file, or
121-
* null if none.
120+
* Gets the cached {@link ScriptInfo} metadata for the script at the given
121+
* file, creating it if it does not already exist.
122122
*/
123123
ScriptInfo getScript(File scriptFile);
124124

0 commit comments

Comments
 (0)