3838import org .scijava .module .ModuleService ;
3939import org .scijava .plugin .Parameter ;
4040import org .scijava .plugin .Plugin ;
41+ import org .scijava .script .ScriptLanguage ;
42+ import org .scijava .script .ScriptService ;
4143
4244/**
4345 * A {@link ScriptProcessor} which parses the {@code #@script} directive.
9799public class ScriptDirectiveScriptProcessor extends DirectiveScriptProcessor {
98100
99101 public ScriptDirectiveScriptProcessor () {
100- super (directive -> "script" . equals ( directive ) );
102+ super ("script" :: equals );
101103 }
102104
103105 @ Parameter
@@ -106,6 +108,9 @@ public ScriptDirectiveScriptProcessor() {
106108 @ Parameter
107109 private ModuleService moduleService ;
108110
111+ @ Parameter
112+ private ScriptService scriptService ;
113+
109114 // -- Internal DirectiveScriptProcessor methods --
110115
111116 @ Override
@@ -125,6 +130,10 @@ private <T> void assignAttribute(final String k, final Object v) {
125130 if (is (k , "name" )) info ().setName (as (v , String .class ));
126131 else if (is (k , "label" )) info ().setLabel (as (v , String .class ));
127132 else if (is (k , "description" )) info ().setDescription (as (v , String .class ));
133+ else if (is (k , "language" )) {
134+ ScriptLanguage lang = parseScriptLanguage (v .toString ());
135+ if (lang != null ) info ().setLanguage (lang );
136+ }
128137 else if (is (k , "menuPath" )) {
129138 info ().setMenuPath (new MenuPath (as (v , String .class )));
130139 }
@@ -161,4 +170,12 @@ private Double priority(final Object p) {
161170 if (lString .matches ("last" )) return Priority .LAST ;
162171 return null ;
163172 }
173+
174+ private ScriptLanguage parseScriptLanguage (final Object v ) {
175+ final String langHint = v .toString ();
176+ ScriptLanguage lang = scriptService .getLanguageByName (langHint );
177+ if (lang == null ) lang = scriptService .getLanguageByExtension (langHint );
178+ if (lang == null ) log .warn ("Unknown script language: " + langHint );
179+ return lang ;
180+ }
164181}
0 commit comments