Skip to content

Commit 599049c

Browse files
gselzerctrueden
authored andcommitted
Rework discovery toward SJC2 removal
We are reworking discovery to work under the following paradigm, which will help to remove the SciJava Common 2 dependency: * SciJava Types: Replace (Default)TypeService with (Default)TypeReifier, discover TypeExtractors using ServiceLoader. * Discoverers: Extract common logic * Rewrite Ops Tests to use StaticDiscoverer under the BarebonesTestEnvironment class * Further SciJava purging * HACK: skip package enforcement See scijava/scijava issue #80 for the reasoning behind this hack * Change up ServiceLoaderDiscoverer syntax to make it easier to call from the module using it.
1 parent 91d3044 commit 599049c

194 files changed

Lines changed: 3733 additions & 4803 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.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,13 @@
139139
requires imglib2.algorithm.fft;
140140
requires mines.jtk;
141141

142+
provides org.scijava.types.TypeExtractor with
143+
net.imagej.ops2.types.ImgFactoryTypeExtractor,
144+
net.imagej.ops2.types.ImgLabelingTypeExtractor,
145+
net.imagej.ops2.types.LabelingMappingTypeExtractor,
146+
net.imagej.ops2.types.OutOfBoundsConstantValueFactoryTypeExtractor,
147+
net.imagej.ops2.types.OutOfBoundsFactoryTypeExtractor,
148+
net.imagej.ops2.types.OutOfBoundsRandomValueFactoryTypeExtractor,
149+
net.imagej.ops2.types.RAITypeExtractor;
150+
142151
}

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/types/ImgFactoryTypeExtractor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
*
5252
* @author Gabriel Selzer
5353
*/
54-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5554
public class ImgFactoryTypeExtractor implements TypeExtractor<ImgFactory<?>> {
5655

5756
@Override
@@ -68,4 +67,12 @@ public Class<ImgFactory<?>> getRawType() {
6867
return (Class) ImgFactory.class;
6968
}
7069

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

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
*
5353
* @author Curtis Rueden
5454
*/
55-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5655
public class ImgLabelingTypeExtractor implements TypeExtractor<ImgLabeling<?, ?>> {
5756

5857
@Override
@@ -78,4 +77,12 @@ public Type reify(final TypeReifier t, final ImgLabeling<?, ?> o, final int n) {
7877
return (Class) ImgLabeling.class;
7978
}
8079

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
*
5252
* @author Curtis Rueden
5353
*/
54-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5554
public class LabelingMappingTypeExtractor implements TypeExtractor<LabelingMapping<?>> {
5655

5756
@Override
@@ -77,4 +76,13 @@ public Class<LabelingMapping<?>> getRawType() {
7776
return (Class) LabelingMapping.class;
7877
}
7978

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

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
*
5353
* @author Gabriel Selzer
5454
*/
55-
@Plugin(type = TypeExtractor.class, priority = Priority.HIGH)
5655
public class NativeImgTypeExtractor implements TypeExtractor<NativeImg<?, ?>> {
5756

5857
@Override
@@ -75,4 +74,13 @@ public Type reify(final TypeReifier t, final NativeImg<?, ?> o, final int n) {
7574
return (Class) NativeImg.class;
7675
}
7776

77+
/**
78+
* Corresponds to org.scijava.Priority.HIGH_PRIORITY
79+
*/
80+
@Override
81+
public double priority() {
82+
return 100;
83+
}
84+
85+
7886
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import net.imglib2.RandomAccessibleInterval;
3737
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory;
3838

39-
import org.scijava.plugin.Plugin;
4039
import org.scijava.types.TypeExtractor;
4140
import org.scijava.types.TypeReifier;
4241
import org.scijava.types.Types;
@@ -47,7 +46,6 @@
4746
*
4847
* @author Gabriel Selzer
4948
*/
50-
@Plugin(type = TypeExtractor.class)
5149
public class OutOfBoundsConstantValueFactoryTypeExtractor
5250
implements TypeExtractor<OutOfBoundsConstantValueFactory<?, ?>> {
5351

@@ -71,4 +69,13 @@ public Type reify(final TypeReifier t, final OutOfBoundsConstantValueFactory<?,
7169
return (Class) OutOfBoundsConstantValueFactory.class;
7270
}
7371

72+
/**
73+
* Corresponds to org.scijava.Priority.NORMAL
74+
*/
75+
@Override
76+
public double priority() {
77+
return 0;
78+
}
79+
80+
7481
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
*
5252
* @author Curtis Rueden
5353
*/
54-
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5554
public class OutOfBoundsFactoryTypeExtractor implements TypeExtractor<OutOfBoundsFactory<?, ?>> {
5655

5756
@Override
@@ -68,4 +67,13 @@ public Type reify(final TypeReifier t, final OutOfBoundsFactory<?, ?> o, final i
6867
return (Class) OutOfBoundsFactory.class;
6968
}
7069

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

0 commit comments

Comments
 (0)