Skip to content

Commit a068418

Browse files
committed
OpWrappers: retain requested type
When we return an Op from the matcher, it is being assigned to a particular Op Type (e.g. BiFunction). We need to remember this type (BiFunction) and not whatever type the Op actually is (i.e. not the net.imagej.ops.math.add.BiFunctionAdder type). This will allow the returned op to be passed back into the matcher with no error
1 parent d1ed79f commit a068418

4 files changed

Lines changed: 699 additions & 3294 deletions

File tree

src/main/java/org/scijava/ops/OpService.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ private Object wrapOp(Object op, OpCandidate match, OpInfo adaptationSrcInfo) {
391391
throw new IllegalArgumentException(
392392
"Matched op Type " + type.getClass() + " matches multiple Op types: " + wrappers.toString());
393393
// get the wrapper and wrap up the Op
394-
return wrap(suitableWrappers[0], op, opInfo);
394+
return wrap(suitableWrappers[0], op, opInfo, match.getRef().getTypes());
395395
} catch (IllegalArgumentException | SecurityException exc) {
396396
log.error(exc.getMessage() != null ? exc.getMessage() : "Cannot wrap " + op.getClass());
397397
return op;
@@ -402,9 +402,10 @@ private Object wrapOp(Object op, OpCandidate match, OpInfo adaptationSrcInfo) {
402402
}
403403

404404
@SuppressWarnings("unchecked")
405-
private <T> T wrap(Class<T> opType, Object op, OpInfo info) {
405+
private <T> T wrap(Class<T> opType, Object op, OpInfo info, Type[] requestedTypes) {
406406
OpWrapper<T> wrapper = (OpWrapper<T>) wrappers.get(opType);
407-
return wrapper.wrap((T) op, info);
407+
//TODO is there a better way to reconcile multiple requested types?
408+
return wrapper.wrap((T) op, info, requestedTypes[0]);
408409
}
409410

410411
public <T> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?> outType) {

0 commit comments

Comments
 (0)