Skip to content

Commit 23eb3f4

Browse files
Treiblesschorlegselzer
authored andcommitted
Add correct indices to OpRef transformation
1 parent 736652c commit 23eb3f4

3 files changed

Lines changed: 26 additions & 12 deletions

File tree

src/main/java/org/scijava/ops/transform/OpRefTransformUtils.java

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,29 @@ private OpRefTransformUtils() {
4848

4949
/**
5050
* Attempts to perform "unlift" transformation of the specified
51-
* {@link OpRef} if it matches the specified classes. Otherwise, null is
52-
* returned, indicating that transformation is not possible.
51+
* {@link OpRef} if it matches the specified classes. Otherwise null is
52+
* returned, indicating that transformation is not possible. If no indices
53+
* are given, all types will be unlifted.
5354
*
54-
* @param toRef the ref to transform
55-
* @param rawSearchClass the functional raw type to look for
56-
* @param unliftRawClass the raw type of types to unlift
55+
* @param toRef
56+
* the ref to transform
57+
* @param rawSearchClass
58+
* the functional raw type to look for
59+
* @param unliftRawClass
60+
* the raw type of types to unlift
61+
* @param typeArgumentIndices
62+
* the indices of type arguments of the functional refTypes to unlift
63+
* @param argIndices
64+
* the indices of arg types of the ref to unlift
65+
* @param outputIndices
66+
* the indices of output types of the ref to unlift
5767
* @return
5868
*/
59-
public static OpRef unliftTransform(OpRef toRef, Class<?> rawSearchClass, Class<?> unliftRawClass) {
69+
public static OpRef unliftTransform(OpRef toRef, Class<?> rawSearchClass, Class<?> unliftRawClass,
70+
Integer[] typeArgumentIndices, Integer[] argIndices, Integer[] outputIndices) {
6071
Type[] refTypes = toRef.getTypes();
61-
boolean typesChanged = TypeModUtils.unliftParameterizedTypes(refTypes, rawSearchClass, unliftRawClass);
72+
boolean typesChanged = TypeModUtils.unliftParameterizedTypes(refTypes, rawSearchClass, unliftRawClass,
73+
typeArgumentIndices);
6274
// TODO We assume here that the functional input is the first Type in
6375
// this list and all others are secondary args if there are any (we do
6476
// not want to touch them as they are not part of op transformations).
@@ -67,9 +79,9 @@ public static OpRef unliftTransform(OpRef toRef, Class<?> rawSearchClass, Class<
6779
// need to be requested first and are thus at the beginning of the list.
6880
// From the functional type we know how many there must be.
6981
Type[] args = toRef.getArgs();
70-
boolean argsChanged = TypeModUtils.unliftTypes(args, unliftRawClass);
82+
boolean argsChanged = TypeModUtils.unliftTypes(args, unliftRawClass, argIndices);
7183
Type[] outs = toRef.getOutTypes();
72-
boolean outsChanged = TypeModUtils.unliftTypes(outs, unliftRawClass);
84+
boolean outsChanged = TypeModUtils.unliftTypes(outs, unliftRawClass, outputIndices);
7385

7486
if (typesChanged && argsChanged && outsChanged) {
7587
return OpRef.fromTypes(toRef.getName(), refTypes, outs, args);

src/main/java/org/scijava/ops/transform/lift/LiftFunctionToIterableTransformer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public Object transform(OpService opService, OpRef fromRef, Object src) {
1919

2020
@Override
2121
public OpRef getRefTransformingTo(OpRef toRef) {
22-
return OpRefTransformUtils.unliftTransform(toRef, Function.class, Iterable.class);
22+
return OpRefTransformUtils.unliftTransform(toRef, Function.class,
23+
Iterable.class, new Integer[]{}, new Integer[]{0}, new Integer[]{ 0 });
2324
}
2425

2526
@Override

src/main/java/org/scijava/ops/transform/lift/LiftFunctionToListTransformer.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ public Object transform(OpService opService, OpRef fromRef, Object src) {
2020

2121
@Override
2222
public OpRef getRefTransformingTo(OpRef toRef) {
23-
return OpRefTransformUtils.unliftTransform(toRef, Function.class, List.class);
23+
return OpRefTransformUtils.unliftTransform(toRef, Function.class, List.class, new Integer[] {},
24+
new Integer[] { 0 }, new Integer[] { 0 });
2425
}
25-
26+
2627
@Override
2728
public Class<?> srcClass() {
2829
return Function.class;

0 commit comments

Comments
 (0)