Skip to content

Commit c2da31b

Browse files
gselzerctrueden
authored andcommitted
Fix to narrow number of matching OpTransformers
Essentially we add in a check that makes sure that the to type that we want is the same as the to type of the OpTransformer. This prevents `BiFunctionToBiComputer` transformers from matching when you require a `Computer`.
1 parent d71b5bb commit c2da31b

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ public static Type replaceRawType(Type type, Class<?> searchClass, Class<?> repl
237237
public static Type[] insert(Type[] types, Type type, int index) {
238238
List<Type> out = new ArrayList<>();
239239
out.addAll(Arrays.asList(types));
240-
out.add(index, type);
240+
if(index < out.size()) out.add(index, type);
241+
else out.add(type);
241242
return out.toArray(new Type[out.size()]);
242243
}
243244

@@ -252,7 +253,7 @@ public static Type[] insert(Type[] types, Type type, int index) {
252253
public static Type[] remove(Type[] types, int index) {
253254
List<Type> out = new ArrayList<>();
254255
out.addAll(Arrays.asList(types));
255-
out.remove(index);
256+
if(index < types.length) out.remove(index);
256257
return out.toArray(new Type[out.size()]);
257258
}
258259

src/main/java/org/scijava/ops/transform/functional/FunctionalTypeTransformer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import org.scijava.ops.matcher.OpRef;
66
import org.scijava.ops.transform.OpTransformer;
77
import org.scijava.ops.transform.TypeModUtils;
8+
import org.scijava.util.Types;
89

910
/**
1011
* Interface for transformers converting between functional Op types.</br>
@@ -17,6 +18,7 @@ public interface FunctionalTypeTransformer extends OpTransformer {
1718
@Override
1819
default OpRef getRefTransformingTo(OpRef toRef) {
1920
Type[] refTypes = toRef.getTypes();
21+
if(Types.raw(refTypes[0]) != targetClass()) return null;
2022
boolean hit = TypeModUtils.replaceRawTypes(refTypes, targetClass(), srcClass());
2123
if (hit) {
2224
return OpRef.fromTypes(toRef.getName(), refTypes, getTransformedOutputTypes(toRef),

0 commit comments

Comments
 (0)