11package org .scijava .ops .transform .functional ;
22
3+ import java .lang .reflect .ParameterizedType ;
34import java .lang .reflect .Type ;
45import java .util .Arrays ;
56import java .util .stream .Stream ;
@@ -41,7 +42,7 @@ public Type[] getTransformedArgTypes(OpRef toRef) {
4142 public Type getTransformedOutputType (OpRef toRef ) {
4243 return toRef .getOutType ();
4344 }
44-
45+
4546 @ Override
4647 public OpRef getRefTransformingTo (OpRef toRef ) {
4748
@@ -52,11 +53,17 @@ public OpRef getRefTransformingTo(OpRef toRef) {
5253 .concat (Arrays .stream (getTransformedArgTypes (toRef )), Arrays .stream (new Type [] {getTransformedOutputType (toRef )}))
5354 .toArray (Type []::new );
5455
55- // parameterize the OpRef types with the 3 BiFunction type parameters
56+ // if toParamTypes does not contain the number of types needed to parameterize
57+ // this op type, return null.
58+ int expectedNumTypes = ((ParameterizedType ) Types .parameterizeRaw (srcClass ())).getActualTypeArguments ().length ;
59+ if (toParamTypes .length != expectedNumTypes )
60+ return null ;
61+
62+ // parameterize the OpRef types with the type parameters of the op
5663 Type [] refTypes = Arrays .stream (toRef .getTypes ())
5764 .map (refType -> Types .parameterize (Types .raw (refType ), toParamTypes )).toArray (Type []::new );
5865
59- // from here it is the s
66+ // if we can make an OpRef out of this, return it. Otherwise return null.
6067 boolean hit = TypeModUtils .replaceRawTypes (refTypes , targetClass (), srcClass ());
6168 if (hit ) {
6269 return OpRef .fromTypes (toRef .getName (), refTypes , getTransformedOutputType (toRef ),
0 commit comments