Skip to content

Commit f697cb1

Browse files
committed
Forward scijava-progress to SciJava Common
1 parent 234a190 commit f697cb1

File tree

16 files changed

+544
-398
lines changed

16 files changed

+544
-398
lines changed

scijava-ops-api/src/main/java/org/scijava/ops/api/RichOp.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public interface RichOp<T> extends GenericTyped {
5252

5353
Hints hints();
5454

55+
String name();
56+
5557
/**
5658
* Getter for this {@link RichOp}'s <b>raw</b> Op instance
5759
*

scijava-ops-engine/src/main/java/org/scijava/ops/engine/OpWrapper.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929

3030
package org.scijava.ops.engine;
3131

32-
import java.lang.reflect.ParameterizedType;
33-
import java.lang.reflect.Type;
34-
35-
import org.scijava.ops.api.Hints;
3632
import org.scijava.ops.api.OpEnvironment;
3733
import org.scijava.ops.api.OpInstance;
3834
import org.scijava.ops.api.RichOp;
3935
import org.scijava.types.Types;
4036

37+
import java.lang.reflect.ParameterizedType;
38+
import java.lang.reflect.Type;
39+
4140
/**
4241
* An object that can wrap an Op into a {@link RichOp}
4342
*
@@ -50,10 +49,11 @@ public interface OpWrapper<T> {
5049
*
5150
* @param op an Op
5251
* @param env the {@link OpEnvironment} that produced the Op
53-
* @param hints the {@link Hints} used to produce the Op
52+
* @param conditions the {@link MatchingConditions} used to produce the Op
5453
* @return a {@link RichOp} wrapping {@code op}
5554
*/
56-
RichOp<T> wrap(OpInstance<T> op, OpEnvironment env, Hints hints);
55+
RichOp<T> wrap(OpInstance<T> op, OpEnvironment env,
56+
MatchingConditions conditions);
5757

5858
default Class<?> type() {
5959
Type wrapperType = getClass().getGenericInterfaces()[0];

scijava-ops-engine/src/main/java/org/scijava/ops/engine/impl/DefaultOpEnvironment.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,12 @@ public <T> T opFromInfoChain(final InfoTree tree, final Nil<T> specialType) {
276276
@SuppressWarnings("unchecked")
277277
OpInstance<T> instance = (OpInstance<T>) tree.newInstance(specialType
278278
.getType());
279-
Hints hints = getDefaultHints();
280-
RichOp<T> wrappedOp = wrapOp(instance, hints);
279+
var conditions = MatchingConditions.from( //
280+
new InfoMatchingOpRequest(tree.info(), Nil.of(tree.info().opType())), //
281+
getDefaultHints() //
282+
);
283+
RichOp<T> wrappedOp = wrapOp(instance, conditions);
281284
return wrappedOp.asOpType();
282-
283285
}
284286

285287
@Override
@@ -540,12 +542,12 @@ private OpInstance<?> instantiateOp(final OpCandidate candidate,
540542
* Wraps the matched op into an Op that knows its generic typing.
541543
*
542544
* @param instance - the {@link OpInstance} to wrap.
543-
* @param hints - the {@link Hints} used to create the {@link OpInstance}
545+
* @param conditions - the {@link Hints} used to create the {@link OpInstance}
544546
* @return an Op wrapping of op.
545547
*/
546548
@SuppressWarnings("unchecked")
547-
private <T> RichOp<T> wrapOp(OpInstance<T> instance, Hints hints)
548-
throws IllegalArgumentException
549+
private <T> RichOp<T> wrapOp(OpInstance<T> instance,
550+
MatchingConditions conditions) throws IllegalArgumentException
549551
{
550552
if (wrappers == null) initWrappers();
551553

@@ -572,7 +574,7 @@ private <T> RichOp<T> wrapOp(OpInstance<T> instance, Hints hints)
572574
// wrap the Op
573575
final OpWrapper<T> opWrapper = (OpWrapper<T>) wrappers.get(Types.raw(
574576
reifiedSuperType));
575-
return opWrapper.wrap(instance, this, hints);
577+
return opWrapper.wrap(instance, this, conditions);
576578
}
577579
catch (IllegalArgumentException | SecurityException exc) {
578580
throw new IllegalArgumentException(exc.getMessage() != null ? exc
@@ -670,11 +672,7 @@ private OpRequest inferOpRequest(OpDependencyMember<?> dependency,
670672

671673
private RichOp<?> wrapViaCache(MatchingConditions conditions) {
672674
OpInstance<?> instance = getInstance(conditions);
673-
return wrap(instance, conditions.hints());
674-
}
675-
676-
private RichOp<?> wrap(OpInstance<?> instance, Hints hints) {
677-
return wrapOp(instance, hints);
675+
return wrapOp(instance, conditions);
678676
}
679677

680678
/**

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/AbstractRichOp.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.scijava.ops.api.OpEnvironment;
3636
import org.scijava.ops.api.OpInstance;
3737
import org.scijava.ops.api.RichOp;
38+
import org.scijava.ops.engine.MatchingConditions;
3839
import org.scijava.progress.Progress;
3940

4041
/**
@@ -51,16 +52,16 @@ public abstract class AbstractRichOp<T> implements RichOp<T> {
5152

5253
private final OpInstance<T> instance;
5354
private final OpEnvironment env;
54-
private final Hints hints;
55+
private final MatchingConditions conditions;
5556

5657
public boolean record = true;
5758

5859
public AbstractRichOp(final OpInstance<T> instance, final OpEnvironment env,
59-
final Hints hints)
60+
final MatchingConditions conditions)
6061
{
6162
this.instance = instance;
6263
this.env = env;
63-
this.hints = hints;
64+
this.conditions = conditions;
6465

6566
this.env.history().logOp(this);
6667
}
@@ -72,7 +73,12 @@ public OpEnvironment env() {
7273

7374
@Override
7475
public Hints hints() {
75-
return hints;
76+
return conditions.hints();
77+
}
78+
79+
@Override
80+
public String name() {
81+
return conditions.request().getName();
7682
}
7783

7884
@Override
@@ -82,7 +88,7 @@ public OpInstance<T> instance() {
8288

8389
@Override
8490
public void preprocess(Object... inputs) {
85-
Progress.register(this);
91+
Progress.register(this, conditions.request().getName());
8692
}
8793

8894
@Override

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/InfoMatchingOpRequest.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,18 @@
2929

3030
package org.scijava.ops.engine.matcher.impl;
3131

32-
import java.lang.reflect.ParameterizedType;
33-
import java.lang.reflect.Type;
34-
import java.lang.reflect.TypeVariable;
35-
import java.util.HashMap;
36-
import java.util.Map;
37-
3832
import org.scijava.ops.api.OpInfo;
3933
import org.scijava.ops.api.OpRequest;
4034
import org.scijava.types.Nil;
4135
import org.scijava.types.Types;
4236
import org.scijava.types.inference.GenericAssignability;
4337

38+
import java.lang.reflect.ParameterizedType;
39+
import java.lang.reflect.Type;
40+
import java.lang.reflect.TypeVariable;
41+
import java.util.HashMap;
42+
import java.util.Map;
43+
4444
public class InfoMatchingOpRequest implements OpRequest {
4545

4646
/** Name of the op, or null for any name. */
@@ -75,10 +75,18 @@ public InfoMatchingOpRequest(OpInfo info, Nil<?> specialType) {
7575
if (!Types.isAssignable(from, this.type, this.map))
7676
throw new IllegalArgumentException();
7777
}
78-
args = info.inputs().stream().map(m -> Types.substituteTypeVariables(m
79-
.getType(), this.map)).toArray(Type[]::new);
80-
outType = Types.substituteTypeVariables(info.output().getType(), this.map);
78+
args = info.inputs().stream().map(m -> mappedType(m.getType(), this.map))
79+
.toArray(Type[]::new);
80+
outType = mappedType(info.outputType(), this.map);
81+
}
8182

83+
private Type mappedType(Type t, Map<TypeVariable<?>, Type> map) {
84+
try {
85+
return Types.substituteTypeVariables(t, map);
86+
}
87+
catch (Exception e) {
88+
return t;
89+
}
8290
}
8391

8492
@Override

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/impl/LossReporterWrapper.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@
2929

3030
package org.scijava.ops.engine.matcher.impl;
3131

32-
import org.scijava.ops.api.Hints;
3332
import org.scijava.ops.api.OpEnvironment;
3433
import org.scijava.ops.api.OpInstance;
3534
import org.scijava.ops.api.RichOp;
35+
import org.scijava.ops.engine.MatchingConditions;
3636
import org.scijava.ops.engine.OpWrapper;
3737
import org.scijava.ops.engine.conversionLoss.LossReporter;
3838
import org.scijava.types.Nil;
@@ -53,15 +53,15 @@ public class LossReporterWrapper<I, O> //
5353
@Override
5454
public RichOp<LossReporter<I, O>> wrap( //
5555
final OpInstance<LossReporter<I, O>> instance, OpEnvironment env,
56-
Hints hints)
56+
MatchingConditions conditions)
5757
{
5858
class GenericTypedLossReporter //
5959
extends AbstractRichOp<LossReporter<I, O>> //
6060
implements LossReporter<I, O> //
6161
{
6262

6363
public GenericTypedLossReporter() {
64-
super(instance, env, hints);
64+
super(instance, env, conditions);
6565
}
6666

6767
@Override

0 commit comments

Comments
 (0)