Skip to content

Commit b821e78

Browse files
committed
Introduce separate @container for computer outputs
They aren't exactly mutable in the same was as the mutable inplace arguments are. Rather, they are preallocated empty containers whose contents will be filled in by the invoked computation. My strong intuition is that having this distinction baked into the type annotations, and accessible at runtime, may be somehow helpful later. This also adds a corresponding ItemIO.CONTAINER value for struct members; the ItemIO.BOTH value is retired in favor of ItemIO.MUTABLE, which corresponds to the @mutable annotation for the Inplace interfaces.
1 parent aa899f9 commit b821e78

12 files changed

Lines changed: 127 additions & 90 deletions

File tree

‎scijava/scijava-ops/src/main/java/org/scijava/ops/function/Computers.java‎

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
import org.scijava.ops.OpEnvironment;
1818
import org.scijava.types.Nil;
19-
import org.scijava.param.Mutable;
19+
import org.scijava.param.Container;
2020
import org.scijava.types.Types;
2121

2222
/**
@@ -207,7 +207,7 @@ public interface Arity0<O> extends
207207
Consumer<O>
208208
{
209209

210-
void compute(@Mutable O out);
210+
void compute(@Container O out);
211211

212212
@Override
213213
default void accept(final O out)
@@ -221,7 +221,7 @@ public interface Arity1<I, O> extends
221221
BiConsumer<I, O>
222222
{
223223

224-
void compute(I in, @Mutable O out);
224+
void compute(I in, @Container O out);
225225

226226
@Override
227227
default void accept(final I in, final O out)
@@ -235,7 +235,7 @@ public interface Arity2<I1, I2, O> extends
235235
Consumers.Arity3<I1, I2, O>
236236
{
237237

238-
void compute(I1 in1, I2 in2, @Mutable O out);
238+
void compute(I1 in1, I2 in2, @Container O out);
239239

240240
@Override
241241
default void accept(final I1 in1, final I2 in2, final O out)
@@ -249,7 +249,7 @@ public interface Arity3<I1, I2, I3, O> extends
249249
Consumers.Arity4<I1, I2, I3, O>
250250
{
251251

252-
void compute(I1 in1, I2 in2, I3 in3, @Mutable O out);
252+
void compute(I1 in1, I2 in2, I3 in3, @Container O out);
253253

254254
@Override
255255
default void accept(final I1 in1, final I2 in2, final I3 in3, final O out)
@@ -263,7 +263,7 @@ public interface Arity4<I1, I2, I3, I4, O> extends
263263
Consumers.Arity5<I1, I2, I3, I4, O>
264264
{
265265

266-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, @Mutable O out);
266+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, @Container O out);
267267

268268
@Override
269269
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final O out)
@@ -277,7 +277,7 @@ public interface Arity5<I1, I2, I3, I4, I5, O> extends
277277
Consumers.Arity6<I1, I2, I3, I4, I5, O>
278278
{
279279

280-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, @Mutable O out);
280+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, @Container O out);
281281

282282
@Override
283283
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final O out)
@@ -291,7 +291,7 @@ public interface Arity6<I1, I2, I3, I4, I5, I6, O> extends
291291
Consumers.Arity7<I1, I2, I3, I4, I5, I6, O>
292292
{
293293

294-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, @Mutable O out);
294+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, @Container O out);
295295

296296
@Override
297297
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final O out)
@@ -305,7 +305,7 @@ public interface Arity7<I1, I2, I3, I4, I5, I6, I7, O> extends
305305
Consumers.Arity8<I1, I2, I3, I4, I5, I6, I7, O>
306306
{
307307

308-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, @Mutable O out);
308+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, @Container O out);
309309

310310
@Override
311311
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final O out)
@@ -319,7 +319,7 @@ public interface Arity8<I1, I2, I3, I4, I5, I6, I7, I8, O> extends
319319
Consumers.Arity9<I1, I2, I3, I4, I5, I6, I7, I8, O>
320320
{
321321

322-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, @Mutable O out);
322+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, @Container O out);
323323

324324
@Override
325325
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final O out)
@@ -333,7 +333,7 @@ public interface Arity9<I1, I2, I3, I4, I5, I6, I7, I8, I9, O> extends
333333
Consumers.Arity10<I1, I2, I3, I4, I5, I6, I7, I8, I9, O>
334334
{
335335

336-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, @Mutable O out);
336+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, @Container O out);
337337

338338
@Override
339339
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final O out)
@@ -347,7 +347,7 @@ public interface Arity10<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, O> extends
347347
Consumers.Arity11<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, O>
348348
{
349349

350-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, @Mutable O out);
350+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, @Container O out);
351351

352352
@Override
353353
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final O out)
@@ -361,7 +361,7 @@ public interface Arity11<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, O> extend
361361
Consumers.Arity12<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, O>
362362
{
363363

364-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, @Mutable O out);
364+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, @Container O out);
365365

366366
@Override
367367
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final O out)
@@ -375,7 +375,7 @@ public interface Arity12<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, O> e
375375
Consumers.Arity13<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, O>
376376
{
377377

378-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, @Mutable O out);
378+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, @Container O out);
379379

380380
@Override
381381
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final O out)
@@ -389,7 +389,7 @@ public interface Arity13<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13,
389389
Consumers.Arity14<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, O>
390390
{
391391

392-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, @Mutable O out);
392+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, @Container O out);
393393

394394
@Override
395395
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final I13 in13, final O out)
@@ -403,7 +403,7 @@ public interface Arity14<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13,
403403
Consumers.Arity15<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, O>
404404
{
405405

406-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, @Mutable O out);
406+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, @Container O out);
407407

408408
@Override
409409
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final I13 in13, final I14 in14, final O out)
@@ -417,7 +417,7 @@ public interface Arity15<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13,
417417
Consumers.Arity16<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, O>
418418
{
419419

420-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, I15 in15, @Mutable O out);
420+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, I15 in15, @Container O out);
421421

422422
@Override
423423
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final I13 in13, final I14 in14, final I15 in15, final O out)
@@ -431,7 +431,7 @@ public interface Arity16<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13,
431431
Consumers.Arity17<I1, I2, I3, I4, I5, I6, I7, I8, I9, I10, I11, I12, I13, I14, I15, I16, O>
432432
{
433433

434-
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, I15 in15, I16 in16, @Mutable O out);
434+
void compute(I1 in1, I2 in2, I3 in3, I4 in4, I5 in5, I6 in6, I7 in7, I8 in8, I9 in9, I10 in10, I11 in11, I12 in12, I13 in13, I14 in14, I15 in15, I16 in16, @Container O out);
435435

436436
@Override
437437
default void accept(final I1 in1, final I2 in2, final I3 in3, final I4 in4, final I5 in5, final I6 in6, final I7 in7, final I8 in8, final I9 in9, final I10 in10, final I11 in11, final I12 in12, final I13 in13, final I14 in14, final I15 in15, final I16 in16, final O out)

‎scijava/scijava-ops/src/main/java/org/scijava/ops/impl/DefaultOpEnvironment.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,8 @@ private OpRef inferOpRef(Type type, String name, Map<TypeVariable<?>, Type> type
638638
if (fmts == null)
639639
return null;
640640

641-
EnumSet<ItemIO> inIos = EnumSet.of(ItemIO.BOTH, ItemIO.INPUT);
642-
EnumSet<ItemIO> outIos = EnumSet.of(ItemIO.BOTH, ItemIO.OUTPUT);
641+
EnumSet<ItemIO> inIos = EnumSet.of(ItemIO.INPUT, ItemIO.CONTAINER, ItemIO.MUTABLE);
642+
EnumSet<ItemIO> outIos = EnumSet.of(ItemIO.OUTPUT, ItemIO.CONTAINER, ItemIO.MUTABLE);
643643

644644
Type[] inputs = fmts.stream().filter(fmt -> inIos.contains(fmt.itemIO())).map(fmt -> fmt.type())
645645
.toArray(Type[]::new);

‎scijava/scijava-ops/src/main/java/org/scijava/ops/simplify/SimplificationUtils.java‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.scijava.ops.matcher.MatchingUtils;
2525
import org.scijava.ops.matcher.OpRef;
2626
import org.scijava.ops.util.AnnotationUtils;
27+
import org.scijava.param.Container;
2728
import org.scijava.param.Mutable;
2829
import org.scijava.param.ParameterStructs;
2930
import org.scijava.types.Nil;
@@ -120,21 +121,23 @@ public static Method findFMethod(Class<?> c) {
120121
}
121122

122123
/**
123-
* Finds the {@link Mutable} argument of a {@link FunctionalInterface}'s
124-
* singular abstract method. If there is no argument annotated with
125-
* {@code Mutable}, then it is assumed that no arguments are mutable and that
126-
* the output of the functional {@link Method} is its output. We also assume
127-
* that only one argument is annotated.
124+
* Finds the {@link Mutable} or {@link Container} argument of a
125+
* {@link FunctionalInterface}'s singular abstract method. If there is no
126+
* argument annotated with {@code Mutable} or {@code Container}, then it is
127+
* assumed that no arguments are mutable and that the output of the functional
128+
* {@link Method} is its output. We also assume that only one argument is
129+
* annotated.
128130
*
129131
* @param c - the {@link Class} extending a {@link FunctionalInterface}
130-
* @return the index of the mutable argument (or -1 iff the output is
131-
* returned).
132+
* @return the index of the mutable argument (or -1 iff the output is returned).
132133
*/
133134
public static int findMutableArgIndex(Class<?> c) {
134135
Method fMethod = findFMethod(c);
135136
for (int i = 0; i < fMethod.getParameterCount(); i++) {
136137
if (AnnotationUtils.getMethodParameterAnnotation(fMethod, i,
137138
Mutable.class) != null) return i;
139+
if (AnnotationUtils.getMethodParameterAnnotation(fMethod, i,
140+
Container.class) != null) return i;
138141
}
139142
return -1;
140143
}

‎scijava/scijava-ops/src/main/java/org/scijava/ops/simplify/SimplifiedOpInfo.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.scijava.ops.matcher.OpMatchingException;
1616
import org.scijava.param.ParameterStructs;
1717
import org.scijava.param.ValidityException;
18-
import org.scijava.struct.ItemIO;
1918
import org.scijava.struct.Member;
2019
import org.scijava.struct.Struct;
2120
import org.scijava.struct.StructInstance;
@@ -81,12 +80,10 @@ public double priority() {
8180
* <li>a penalty defined as a lossiness heuristic of this simplification. This
8281
* penalty is the sum of:
8382
* <ul>
84-
* <li>the loss undertaken by converting each of the Op's inputs (as defined
85-
* by an {@link ItemIO#INPUT} or {@link ItemIO#BOTH} annotation) from the ref
83+
* <li>the loss undertaken by converting each of the Op's inputs from the ref
8684
* type to the info type
87-
* <li>the loss undertaken by converting each of the Op's outputs (as defined
88-
* by an {@link ItemIO#OUTPUT} or {@link ItemIO#BOTH} annotation) from the
89-
* info type to the ref type
85+
* <li>the loss undertaken by converting each of the Op's outputs from the info
86+
* type to the ref type
9087
* </ul>
9188
* </ul>
9289
*/

‎scijava/scijava-ops/src/main/java/org/scijava/ops/util/Inject.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public static boolean isInjectable(final StructInstance<?> instance) {
3333
public static void inputs(StructInstance<?> instance, Object... objs) {
3434
unsafe(filterAccessibles(getAccessibles(instance), m -> {
3535
ItemIO ioType = m.member().getIOType();
36-
return EnumSet.of(ItemIO.BOTH, ItemIO.INPUT).contains(ioType);
36+
return EnumSet.of(ItemIO.INPUT, ItemIO.CONTAINER, ItemIO.MUTABLE).contains(ioType);
3737
}), objs);
3838
}
3939

4040
public static void outputs(StructInstance<?> instance, Object... objs) {
4141
unsafe(filterAccessibles(getAccessibles(instance), m -> {
4242
ItemIO ioType = m.member().getIOType();
43-
return EnumSet.of(ItemIO.BOTH, ItemIO.OUTPUT).contains(ioType);
43+
return EnumSet.of(ItemIO.OUTPUT, ItemIO.CONTAINER, ItemIO.MUTABLE).contains(ioType);
4444
}), objs);
4545
}
4646

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package org.scijava.param;
2+
3+
import java.lang.annotation.ElementType;
4+
import java.lang.annotation.Retention;
5+
import java.lang.annotation.RetentionPolicy;
6+
import java.lang.annotation.Target;
7+
8+
/**
9+
* Annotation to mark a parameter as a container: the value of the given
10+
* argument will be populated by the algorithm during execution.
11+
*
12+
* @see Computers
13+
*/
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Target(ElementType.TYPE_USE)
16+
public @interface Container {
17+
18+
}

‎scijava/scijava-ops/src/main/java/org/scijava/param/ParameterStructs.java‎

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import io.leangen.geantyref.AnnotationFormatException;
55
import io.leangen.geantyref.TypeFactory;
66

7-
import java.lang.annotation.Annotation;
87
import java.lang.reflect.AnnotatedElement;
98
import java.lang.reflect.Field;
109
import java.lang.reflect.Method;
@@ -325,14 +324,16 @@ public static List<Member<?>> parse(final OpInfo opInfo, final List<Simplifier<?
325324
}
326325

327326
/**
328-
* Returns a list of {@link FunctionalMethodType}s describing the input and output
329-
* types of the functional method of the specified functional type. In doing so,
330-
* the return type of the method will me marked as {@link ItemIO#OUTPUT} and the
331-
* all method parameters as {@link ItemIO#OUTPUT}, except for parameters annotated
332-
* with {@link Mutable} which will be marked as {@link ItemIO#BOTH}. If the specified
333-
* type does not have a functional method in its hierarchy, null will be
334-
* returned.<br>
335-
* The order will be the following: method parameters from left to right, return type
327+
* Returns a list of {@link FunctionalMethodType}s describing the input and
328+
* output types of the functional method of the specified functional type. In
329+
* doing so, the return type of the method will me marked as
330+
* {@link ItemIO#OUTPUT} and the all method parameters as {@link ItemIO#OUTPUT},
331+
* except for parameters annotated with {@link Container} or {@link Mutable}
332+
* which will be marked as {@link ItemIO#CONTAINER} or {@link ItemIO#MUTABLE}
333+
* respectively. If the specified type does not have a functional method in its
334+
* hierarchy, {@code null} will be returned.<br>
335+
* The order will be the following: method parameters from left to right, then
336+
* return type.
336337
*
337338
* @param functionalType
338339
* @return
@@ -349,8 +350,14 @@ public static List<FunctionalMethodType> findFunctionalMethodTypes(Type function
349350
List<FunctionalMethodType> out = new ArrayList<>();
350351
int i = 0;
351352
for (Type t : Types.getExactParameterTypes(functionalMethod, paramfunctionalType)) {
352-
boolean isMutable = AnnotationUtils.getMethodParameterAnnotation(functionalMethod, i, Mutable.class) != null;
353-
out.add(new FunctionalMethodType(t, isMutable ? ItemIO.BOTH : ItemIO.INPUT));
353+
final ItemIO ioType;
354+
if (AnnotationUtils.getMethodParameterAnnotation(functionalMethod, i, Container.class) != null)
355+
ioType = ItemIO.CONTAINER;
356+
else if (AnnotationUtils.getMethodParameterAnnotation(functionalMethod, i, Mutable.class) != null)
357+
ioType = ItemIO.MUTABLE;
358+
else
359+
ioType = ItemIO.INPUT;
360+
out.add(new FunctionalMethodType(t, ioType));
354361
i++;
355362
}
356363

@@ -391,9 +398,10 @@ private static void checkModifiers(String message, final ArrayList<ValidityProbl
391398
/**
392399
* Create new instances of {@link Parameter} annotations having default names (key) and the {@link ItemIO}
393400
* from the specified list of {@link FunctionalMethodType}s. Default names will be:<br><br>
394-
* 'mutable{index}' for {@link ItemIO#BOTH}<br>
395401
* 'input{index}' for {@link ItemIO#INPUT}<br>
396-
* 'output{index}' for {@link ItemIO#OUTPUT}<br><br>
402+
* 'output{index}' for {@link ItemIO#OUTPUT}<br>
403+
* 'container{index}' for {@link ItemIO#CONTAINER}<br>
404+
* 'mutable{index}' for {@link ItemIO#MUTABLE}<br><br>
397405
* with {index} being counted individually.
398406
*
399407
* This is used to infer the annotations for {@link FunctionalParameterMember}s if the {@link Parameter} is not
@@ -405,25 +413,25 @@ private static void checkModifiers(String message, final ArrayList<ValidityProbl
405413
private static Parameter[] synthesizeParameterAnnotations(final List<FunctionalMethodType> fmts) {
406414
List<Parameter> params = new ArrayList<>();
407415

408-
int ins, outs, insOuts;
409-
ins = outs = insOuts = 1;
416+
int ins, outs, containers, mutables;
417+
ins = outs = containers = mutables = 1;
410418
for (FunctionalMethodType fmt : fmts) {
411419
Map<String, Object> paramValues = new HashMap<>();
412420
paramValues.put(Parameter.ITEMIO_FIELD_NAME, fmt.itemIO());
413421

414422
String key;
415423
switch (fmt.itemIO()) {
416-
case BOTH:
417-
key = "mutable" + insOuts;
418-
insOuts++;
419-
break;
420424
case INPUT:
421-
key = "input" + ins;
422-
ins++;
425+
key = "input" + ins++;
423426
break;
424427
case OUTPUT:
425-
key = "output" + outs;
426-
outs++;
428+
key = "output" + outs++;
429+
break;
430+
case CONTAINER:
431+
key = "container" + containers++;
432+
break;
433+
case MUTABLE:
434+
key = "mutable" + mutables++;
427435
break;
428436
default:
429437
throw new RuntimeException("Unexpected ItemIO type encountered!");
@@ -639,11 +647,11 @@ private static boolean checkValidity(Parameter param, String name,
639647
valid = false;
640648
}
641649

642-
if (param.itemIO() == ItemIO.BOTH && isImmutable(type)) {
643-
// NB: The BOTH type signifies that the parameter will be changed
644-
// in-place somehow. But immutable parameters cannot be changed in
645-
// such a manner, so it makes no sense to label them as BOTH.
646-
final String error = "Immutable BOTH parameter: " + name + " (" + type.getName() + " is immutable)";
650+
if ((param.itemIO() == ItemIO.MUTABLE || param.itemIO() == ItemIO.CONTAINER) && isImmutable(type)) {
651+
// NB: The MUTABLE and CONTAINER types signify that the parameter
652+
// will be written to, but immutable parameters cannot be changed in
653+
// such a manner, so it makes no sense to label them as such.
654+
final String error = "Immutable " + param.itemIO() + " parameter: " + name + " (" + type.getName() + " is immutable)";
647655
problems.add(new ValidityProblem(error));
648656
valid = false;
649657
}

0 commit comments

Comments
 (0)