Skip to content

Commit 72176fd

Browse files
authored
Merge pull request #48 from scijava/scijava/scijava-ops-engine/explicit-op-environment
Rewrite SciJava Ops Engine Ops as Services
2 parents 69e2472 + c9d46d6 commit 72176fd

235 files changed

Lines changed: 5961 additions & 3119 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ target/
88

99
# IntelliJ #
1010
.idea/
11-
.iml
11+
*.iml

imagej/imagej-ops2/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,13 @@
326326

327327
<!-- Test scope dependencies -->
328328
<dependency>
329-
<groupId>junit</groupId>
330-
<artifactId>junit</artifactId>
329+
<groupId>org.junit.jupiter</groupId>
330+
<artifactId>junit-jupiter-api</artifactId>
331331
<scope>test</scope>
332332
</dependency>
333333
<dependency>
334334
<groupId>org.junit.jupiter</groupId>
335-
<artifactId>junit-jupiter-api</artifactId>
335+
<artifactId>junit-jupiter-engine</artifactId>
336336
<scope>test</scope>
337337
</dependency>
338338
<dependency>

imagej/imagej-ops2/src/main/java/module-info.java

Lines changed: 122 additions & 113 deletions
Large diffs are not rendered by default.

imagej/imagej-ops2/src/main/java/net/imagej/ops2/eval/DefaultEval.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.Map;
3333

3434
import org.scijava.function.Functions;
35-
import org.scijava.ops.engine.OpService;
35+
import org.scijava.ops.api.OpEnvironment;
3636
import org.scijava.ops.spi.Op;
3737
import org.scijava.plugin.Plugin;
3838

@@ -48,7 +48,7 @@
4848
* @see OpEvaluator
4949
*/
5050
@Plugin(type = Op.class, name = "eval")
51-
public class DefaultEval implements Functions.Arity3<String, Map<String, Object>, OpService, Object>
51+
public class DefaultEval implements Functions.Arity3<String, Map<String, Object>, OpEnvironment, Object>
5252
{
5353

5454
/**
@@ -60,7 +60,7 @@ public class DefaultEval implements Functions.Arity3<String, Map<String, Object>
6060
* @return the output
6161
*/
6262
@Override
63-
public Object apply(final String input, final Map<String, Object> vars, final OpService ops) {
63+
public Object apply(final String input, final Map<String, Object> vars, final OpEnvironment ops) {
6464
OpEvaluator e = new OpEvaluator(ops);
6565
if (vars != null) e.setAll(vars);
6666
return e.evaluate(input);

imagej/imagej-ops2/src/main/java/net/imagej/ops2/eval/OpEvaluator.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import java.util.Map;
3838

3939
import org.scijava.function.Functions;
40-
import org.scijava.ops.engine.OpService;
40+
import org.scijava.ops.api.OpEnvironment;
4141
import org.scijava.ops.engine.util.FunctionUtils;
4242
import org.scijava.ops.spi.Op;
4343
import org.scijava.parsington.Operator;
@@ -46,7 +46,6 @@
4646
import org.scijava.parsington.eval.AbstractStandardStackEvaluator;
4747
import org.scijava.parsington.eval.Evaluator;
4848
import org.scijava.types.Nil;
49-
import org.scijava.types.TypeService;
5049

5150
/**
5251
* A Parsington {@link Evaluator} using available {@link Op}s.
@@ -55,12 +54,12 @@
5554
*/
5655
public class OpEvaluator extends AbstractStandardStackEvaluator {
5756

58-
private final OpService ops;
57+
private final OpEnvironment ops;
5958

6059
/** Map of Parsington {@link Operator}s to Ops operation names. */
6160
private final HashMap<Operator, String> opMap;
6261

63-
public OpEvaluator(final OpService ops) {
62+
public OpEvaluator(final OpEnvironment ops) {
6463
this.ops = ops;
6564
opMap = new HashMap<>();
6665

@@ -150,13 +149,13 @@ public Object execute(final String opName, final Object... args) {
150149
Nil<Object> outType = new Nil<>() {};
151150

152151
// Try executing the op.
153-
Functions.ArityN<Object> func = FunctionUtils.matchN(ops.env(), opName, outType, inTypes);
152+
Functions.ArityN<Object> func = FunctionUtils.matchN(ops, opName, outType, inTypes);
154153
return func.apply(argValues);
155154
}
156155

157156
@SuppressWarnings({ "unchecked" })
158157
private <T> Nil<T> type(Object obj) {
159-
return (Nil<T>) Nil.of(ops.context().service(TypeService.class).reify(obj));
158+
return (Nil<T>) Nil.of(ops.genericType(obj));
160159
}
161160

162161
/** Gets the op name associated with the given {@link Operator}. */
@@ -411,8 +410,8 @@ public Object execute(final Operator op, final Deque<Object> stack) {
411410

412411
// Try the base execute, which handles assignment-oriented operations.
413412
// (NB: super.execute pops the arguments again, so put them back first.)
414-
for (int i = 0; i < args.length; i++) {
415-
stack.push(args[i]);
413+
for (Object arg : args) {
414+
stack.push(arg);
416415
}
417416
final Object result = super.execute(op, stack);
418417
if (result != null) return result;

imagej/imagej-ops2/src/main/java/net/imagej/ops2/image/integral/AbstractIntegralImg.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
* The type of the input image.
4848
* @author Stefan Helfrich (University of Konstanz)
4949
*/
50-
@Plugin(type = OpCollection.class)
5150
public abstract class AbstractIntegralImg<I extends RealType<I>, O extends RealType<O>>
5251
implements Computers.Arity1<RandomAccessibleInterval<I>, RandomAccessibleInterval<O>> {
5352

imagej/imagej-ops2/src/main/java/net/imagej/ops2/labeling/ImgLabelingTypeExtractor.java

Lines changed: 0 additions & 85 deletions
This file was deleted.

imagej/imagej-ops2/src/main/java/net/imagej/ops2/types/ImgFactoryTypeExtractor.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
import net.imglib2.img.array.ArrayImg;
3838

3939
import org.scijava.Priority;
40-
import org.scijava.types.TypeExtractor;
41-
import org.scijava.types.TypeService;
42-
import org.scijava.plugin.Parameter;
4340
import org.scijava.plugin.Plugin;
41+
import org.scijava.types.TypeExtractor;
42+
import org.scijava.types.TypeReifier;
4443

4544
/**
4645
* {@link TypeExtractor} plugin which operates on {@link ArrayImg} objects.
@@ -52,18 +51,14 @@
5251
*
5352
* @author Gabriel Selzer
5453
*/
55-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5654
public class ImgFactoryTypeExtractor implements TypeExtractor<ImgFactory<?>> {
5755

58-
@Parameter
59-
private TypeService typeService;
60-
6156
@Override
62-
public Type reify(final ImgFactory<?> o, final int n) {
57+
public Type reify(final TypeReifier t, final ImgFactory<?> o, final int n) {
6358
if (n != 0)
6459
throw new IndexOutOfBoundsException();
6560

66-
return typeService.reify(o.type());
61+
return t.reify(o.type());
6762
}
6863

6964
@Override
@@ -72,4 +67,12 @@ public Class<ImgFactory<?>> getRawType() {
7267
return (Class) ImgFactory.class;
7368
}
7469

70+
/**
71+
* Corresponds to org.scijava.Priority.LOW_PRIORITY
72+
*/
73+
@Override
74+
public double priority() {
75+
return -100;
76+
}
77+
7578
}

imagej/imagej-ops2/src/main/java/net/imagej/ops2/types/ImgLabelingTypeExtractor.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
import net.imglib2.view.Views;
3939

4040
import org.scijava.Priority;
41-
import org.scijava.types.TypeExtractor;
42-
import org.scijava.types.TypeService;
43-
import org.scijava.plugin.Parameter;
4441
import org.scijava.plugin.Plugin;
42+
import org.scijava.types.TypeExtractor;
43+
import org.scijava.types.TypeReifier;
4544

4645
/**
4746
* {@link TypeExtractor} plugin which operates on {@link Iterable} objects.
@@ -53,27 +52,23 @@
5352
*
5453
* @author Curtis Rueden
5554
*/
56-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5755
public class ImgLabelingTypeExtractor implements TypeExtractor<ImgLabeling<?, ?>> {
5856

59-
@Parameter
60-
private TypeService typeService;
61-
6257
@Override
63-
public Type reify(final ImgLabeling<?, ?> o, final int n) {
58+
public Type reify(final TypeReifier t, final ImgLabeling<?, ?> o, final int n) {
6459
if (n < 0 || n > 1) throw new IndexOutOfBoundsException();
6560

6661
if(n == 0) {
6762
// o.firstElement will return a LabelingType
68-
Type labelingType = typeService.reify(o.firstElement());
63+
Type labelingType = t.reify(o.firstElement());
6964
// sanity check
7065
if(!(labelingType instanceof ParameterizedType)) throw new IllegalArgumentException("ImgLabeling is not of a LabelingType");
7166
// get type arg of labelingType
7267
ParameterizedType pType = (ParameterizedType) labelingType;
7368
return pType.getActualTypeArguments()[0];
7469
}
7570
// otherwise n == 1
76-
return typeService.reify(Views.iterable(o.getSource()).firstElement());
71+
return t.reify(Views.iterable(o.getSource()).firstElement());
7772
}
7873

7974
@Override
@@ -82,4 +77,12 @@ public Type reify(final ImgLabeling<?, ?> o, final int n) {
8277
return (Class) ImgLabeling.class;
8378
}
8479

80+
/**
81+
* Corresponds to org.scijava.Priority.LOW_PRIORITY
82+
*/
83+
@Override
84+
public double priority() {
85+
return -100;
86+
}
87+
8588
}

imagej/imagej-ops2/src/main/java/net/imagej/ops2/types/LabelingMappingTypeExtractor.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
import net.imglib2.roi.labeling.LabelingMapping;
3838

3939
import org.scijava.Priority;
40-
import org.scijava.types.TypeExtractor;
41-
import org.scijava.types.TypeService;
42-
import org.scijava.plugin.Parameter;
4340
import org.scijava.plugin.Plugin;
41+
import org.scijava.types.TypeExtractor;
42+
import org.scijava.types.TypeReifier;
4443

4544
/**
4645
* {@link TypeExtractor} plugin which operates on {@link Iterable} objects.
@@ -52,21 +51,17 @@
5251
*
5352
* @author Curtis Rueden
5453
*/
55-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5654
public class LabelingMappingTypeExtractor implements TypeExtractor<LabelingMapping<?>> {
5755

58-
@Parameter
59-
private TypeService typeService;
60-
6156
@Override
62-
public Type reify(final LabelingMapping<?> o, final int n) {
57+
public Type reify(final TypeReifier t, final LabelingMapping<?> o, final int n) {
6358
if (n != 0)
6459
throw new IndexOutOfBoundsException();
6560

6661
// determine the type arg of the mapping through looking at the Set of Labels
6762
// (o.getLabels() returns a Set<T>, which can be reified by another TypeService
6863
// plugin).
69-
Type labelingMappingSet = typeService.reify(o.getLabels());
64+
Type labelingMappingSet = t.reify(o.getLabels());
7065
// sanity check, argType will always be a set so argType should always be a
7166
// ParameterizedType
7267
if (!(labelingMappingSet instanceof ParameterizedType))
@@ -81,4 +76,13 @@ public Class<LabelingMapping<?>> getRawType() {
8176
return (Class) LabelingMapping.class;
8277
}
8378

79+
/**
80+
* Corresponds to org.scijava.Priority.LOW_PRIORITY
81+
*/
82+
@Override
83+
public double priority() {
84+
return -100;
85+
}
86+
87+
8488
}

0 commit comments

Comments
 (0)