Skip to content

Commit be41b8e

Browse files
committed
ScriptInfo: support all attrs
When an arbitrary key/value pair is given, we should set it as an attribute rather than throwing an exception. In Java, the way these are specified is rather verbose: @parameter(attrs = { @attr(name="foo", value="bar") }) private int value; But for scripts, it is now not only possible, but much more succinct: // @int value(foo="bar") Noticed by Gabriel Einsdorf.
1 parent afab5fd commit be41b8e

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ private void addReturnValue() throws ScriptException {
399399
}
400400

401401
private <T> void addItem(final String name, final Class<T> type,
402-
final Map<String, Object> attrs) throws ScriptException
402+
final Map<String, Object> attrs)
403403
{
404404
final DefaultMutableModuleItem<T> item =
405405
new DefaultMutableModuleItem<T>(this, name, type);
@@ -412,7 +412,7 @@ private <T> void addItem(final String name, final Class<T> type,
412412
}
413413

414414
private <T> void assignAttribute(final DefaultMutableModuleItem<T> item,
415-
final String k, final Object v) throws ScriptException
415+
final String k, final Object v)
416416
{
417417
// CTR: There must be an easier way to do this.
418418
// Just compile the thing using javac? Or parse via javascript, maybe?
@@ -435,7 +435,7 @@ private <T> void assignAttribute(final DefaultMutableModuleItem<T> item,
435435
else if (is(k, "style")) item.setWidgetStyle(as(v, String.class));
436436
else if (is(k, "visibility")) item.setVisibility(as(v, ItemVisibility.class));
437437
else if (is(k, "value")) item.setDefaultValue(as(v, item.getType()));
438-
else throw new ScriptException("Invalid attribute name: " + k);
438+
else item.set(k, v.toString());
439439
}
440440

441441
/** Super terse comparison helper method. */

0 commit comments

Comments
 (0)