Skip to content

Commit 43d8ecc

Browse files
committed
Allow Dependencies to not be adaptable
1 parent 51d3265 commit 43d8ecc

5 files changed

Lines changed: 18 additions & 5 deletions

File tree

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ public OpDependency getAnnotation() {
6161
public String getDependencyName() {
6262
return annotation.name();
6363
}
64+
65+
@Override
66+
public boolean isAdaptable() {
67+
return annotation.adaptable();
68+
}
6469

6570
// -- Member methods --
6671

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212

1313
/** The name of the Op to inject. */
1414
String name();
15+
16+
/** Set to false if the dependency should not be adapted */
17+
boolean adaptable() default true;
1518
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
public interface OpDependencyMember<T> extends Member<T> {
4040

4141
String getDependencyName();
42+
43+
boolean isAdaptable();
4244

4345
// -- Member methods --
4446

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ private List<Object> resolveOpDependencies(OpCandidate op) throws OpMatchingExce
242242
+ "method inputs and outputs of Op dependency field: " + dependency.getKey());
243243
}
244244
try {
245-
resolvedDependencies.add(findOpInstance(dependencyName, inferredRef));
245+
resolvedDependencies.add(findOpInstance(dependencyName, inferredRef, dependency.isAdaptable()));
246246
} catch (final Exception e) {
247247
throw new OpMatchingException("Could not find Op that matches requested Op dependency:" + "\nOp class: "
248248
+ op.opInfo().implementationName() + //
@@ -258,10 +258,10 @@ public <T> T findOpInstance(final String opName, final Nil<T> specialType, final
258258
final Nil<?> outType) {
259259
final OpRef ref = OpRef.fromTypes(opName, toTypes(specialType), outType != null ? outType.getType() : null,
260260
toTypes(inTypes));
261-
return (T) findOpInstance(opName, ref);
261+
return (T) findOpInstance(opName, ref, true);
262262
}
263263

264-
public Object findOpInstance(final String opName, final OpRef ref) {
264+
public Object findOpInstance(final String opName, final OpRef ref, boolean adaptable) {
265265
Object op = null;
266266
OpCandidate match = null;
267267
OpTransformationCandidate transformation = null;
@@ -272,6 +272,9 @@ public Object findOpInstance(final String opName, final OpRef ref) {
272272
op = match.createOp(dependencies);
273273
} catch (OpMatchingException e) {
274274
log.debug("No matching Op for request: " + ref + "\n");
275+
if(adaptable == false) {
276+
throw new IllegalArgumentException(opName + " cannot be adapted (adaptation is disabled)");
277+
}
275278
log.debug("Attempting Op transformation...");
276279

277280
// If we can't find an op matching the original request, we try to find a

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,13 @@ private static Object findInputAwareCreate(final OpService ops, final Class<?> c
137137
Type[]::new);
138138
final Type createOpType = Types.parameterize(createOpRawType, paramTypes);
139139
final OpRef opRef = OpRef.fromTypes(CREATE_OP_NAME, new Type[] { createOpType }, outputParamType, inputParamTypes);
140-
return ops.findOpInstance(CREATE_OP_NAME, opRef);
140+
return ops.findOpInstance(CREATE_OP_NAME, opRef, true);
141141
}
142142

143143
private static Producer<?> findCreate(final OpService ops, final Type outputParamType) {
144144
final Type createOpType = Types.parameterize(Producer.class, new Type[] { outputParamType });
145145
final OpRef opRef = OpRef.fromTypes(CREATE_OP_NAME, new Type[] { createOpType }, outputParamType);
146-
return (Producer<?>) ops.findOpInstance(CREATE_OP_NAME, opRef);
146+
return (Producer<?>) ops.findOpInstance(CREATE_OP_NAME, opRef, true);
147147
}
148148

149149
private static <I, O> Function<I, O> computerToFunction(final Computers.Arity1<I, O> src, final Object inputAwareCreate,

0 commit comments

Comments
 (0)