Skip to content

Commit 6b44821

Browse files
committed
ParameterScriptProcessor: default type as Object
Now you can leave off the type, saying only e.g.: #@output thing And it will implicitly mean: #@output Object thing This is useful if you are too lazy to specify your output types, or you don't know in advance what it will be, or the type would be some obnoxiously long fully qualified class name like java.util.function.Function.
1 parent 702baa9 commit 6b44821

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/main/java/org/scijava/script/process/ParameterScriptProcessor.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@
6262
* supported:
6363
* </p>
6464
* <ul>
65-
* <li>{@code #@<type> <varName>}</li>
66-
* <li>{@code #@<type>(<attr1>=<value1>, ..., <attrN>=<valueN>) <varName>}</li>
65+
* <li>{@code #@ <type> <varName>}</li>
66+
* <li>{@code #@ <type>(<attr1>=<value1>, ..., <attrN>=<valueN>) <varName>}</li>
67+
* <li>{@code #@<IOType> <varName>}</li>
6768
* <li>{@code #@<IOType> <type> <varName>}</li>
6869
* <li>{@code #@<IOType>(<attr1>=<value1>, ..., <attrN>=<valueN>) <type>
6970
* <varName>}</li>
@@ -77,7 +78,8 @@
7778
* <li>{@code <IOType>} - one of {@code INPUT}, {@code OUTPUT}, or {@code BOTH}.
7879
* </li>
7980
* <li>{@code <varName>} - the name of the input or output variable.</li>
80-
* <li>{@code <type>} - the Java {@link Class} of the variable.</li>
81+
* <li>{@code <type>} - the Java {@link Class} of the variable, or
82+
* {@link Object} if none specified.</li>
8183
* <li>{@code <attr*>} - an attribute key.</li>
8284
* <li>{@code <value*>} - an attribute value.</li>
8385
* </ul>
@@ -90,9 +92,9 @@
9092
* <ul>
9193
* <li>{@code #@Dataset dataset}</li>
9294
* <li>{@code #@double(type=OUTPUT) result}</li>
93-
* <li>{@code #@BOTH ImageDisplay display}</li>
94-
* <li>{@code #@INPUT(persist=false, visibility=INVISIBLE) boolean verbose}
95-
* </li>
95+
* <li>{@code #@both ImageDisplay display}</li>
96+
* <li>{@code #@input(persist=false, visibility=INVISIBLE) boolean verbose}</li>
97+
* <li>{@code #@output thing}</li>
9698
* </ul>
9799
* <p>
98100
* Parameters will be parsed and filled just like @{@link Parameter}-annotated
@@ -187,11 +189,18 @@ private boolean parseParam(final String param,
187189
final String typeName, varName;
188190
final String maybeIOType = tokens[0].toUpperCase();
189191
if (isIOType(maybeIOType)) {
190-
// assume syntax: <IOType> <type> <varName>
191-
if (tokens.length < 3) return false;
192+
if (tokens.length == 2) {
193+
// <IOType> <varName>
194+
typeName = "Object";
195+
varName = tokens[1];
196+
}
197+
else if (tokens.length == 3) {
198+
// <IOType> <type> <varName>
199+
typeName = tokens[1];
200+
varName = tokens[2];
201+
}
202+
else return false;
192203
attrs.put("type", maybeIOType);
193-
typeName = tokens[1];
194-
varName = tokens[2];
195204
}
196205
else {
197206
// assume syntax: <type> <varName>

0 commit comments

Comments
 (0)