Skip to content

Commit b3350dd

Browse files
gselzerctrueden
authored andcommitted
Refactor TypeService into TypeReifier
The goal is to remove the SciJava Common dependency on SciJava Types This commit rewrites all Plugin-based TypeExtractors to Services that can be loaded through ServiceLoader.
1 parent 49cd928 commit b3350dd

33 files changed

Lines changed: 1482 additions & 677 deletions

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: 4 additions & 8 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.
@@ -55,15 +54,12 @@
5554
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5655
public class ImgFactoryTypeExtractor implements TypeExtractor<ImgFactory<?>> {
5756

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

66-
return typeService.reify(o.type());
62+
return t.reify(o.type());
6763
}
6864

6965
@Override

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

Lines changed: 5 additions & 9 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.
@@ -56,24 +55,21 @@
5655
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5756
public class ImgLabelingTypeExtractor implements TypeExtractor<ImgLabeling<?, ?>> {
5857

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

6662
if(n == 0) {
6763
// o.firstElement will return a LabelingType
68-
Type labelingType = typeService.reify(o.firstElement());
64+
Type labelingType = t.reify(o.firstElement());
6965
// sanity check
7066
if(!(labelingType instanceof ParameterizedType)) throw new IllegalArgumentException("ImgLabeling is not of a LabelingType");
7167
// get type arg of labelingType
7268
ParameterizedType pType = (ParameterizedType) labelingType;
7369
return pType.getActualTypeArguments()[0];
7470
}
7571
// otherwise n == 1
76-
return typeService.reify(Views.iterable(o.getSource()).firstElement());
72+
return t.reify(Views.iterable(o.getSource()).firstElement());
7773
}
7874

7975
@Override

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

Lines changed: 4 additions & 8 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.
@@ -55,18 +54,15 @@
5554
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5655
public class LabelingMappingTypeExtractor implements TypeExtractor<LabelingMapping<?>> {
5756

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

6662
// determine the type arg of the mapping through looking at the Set of Labels
6763
// (o.getLabels() returns a Set<T>, which can be reified by another TypeService
6864
// plugin).
69-
Type labelingMappingSet = typeService.reify(o.getLabels());
65+
Type labelingMappingSet = t.reify(o.getLabels());
7066
// sanity check, argType will always be a set so argType should always be a
7167
// ParameterizedType
7268
if (!(labelingMappingSet instanceof ParameterizedType))

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@
3636
import net.imglib2.img.NativeImg;
3737

3838
import org.scijava.Priority;
39-
import org.scijava.plugin.Parameter;
4039
import org.scijava.plugin.Plugin;
4140
import org.scijava.types.TypeExtractor;
42-
import org.scijava.types.TypeService;
41+
import org.scijava.types.TypeReifier;
4342

4443
/**
4544
* {@link TypeExtractor} plugin which operates on {@link NativeImg} objects.
@@ -56,21 +55,18 @@
5655
@Plugin(type = TypeExtractor.class, priority = Priority.HIGH)
5756
public class NativeImgTypeExtractor implements TypeExtractor<NativeImg<?, ?>> {
5857

59-
@Parameter
60-
private TypeService typeService;
61-
6258
@Override
63-
public Type reify(final NativeImg<?, ?> o, final int n) {
59+
public Type reify(final TypeReifier t, final NativeImg<?, ?> o, final int n) {
6460
if (n < 0 || n > 1)
6561
throw new IndexOutOfBoundsException();
6662

6763
// type of the image
6864
if (n == 0) {
69-
Type labelingType = typeService.reify(o.firstElement());
65+
Type labelingType = t.reify(o.firstElement());
7066
return labelingType;
7167
}
7268
// type of the backing array
73-
return typeService.reify(o.update(o.cursor()));
69+
return t.reify(o.update(o.cursor()));
7470
}
7571

7672
@Override

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

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

39-
import org.scijava.types.TypeExtractor;
40-
import org.scijava.types.TypeService;
41-
import org.scijava.plugin.Parameter;
4239
import org.scijava.plugin.Plugin;
40+
import org.scijava.types.TypeExtractor;
41+
import org.scijava.types.TypeReifier;
4342
import org.scijava.types.Types;
4443

4544
/**
@@ -52,15 +51,12 @@
5251
public class OutOfBoundsConstantValueFactoryTypeExtractor
5352
implements TypeExtractor<OutOfBoundsConstantValueFactory<?, ?>> {
5453

55-
@Parameter
56-
private TypeService typeService;
57-
5854
@Override
59-
public Type reify(final OutOfBoundsConstantValueFactory<?, ?> o, final int n) {
55+
public Type reify(final TypeReifier t, final OutOfBoundsConstantValueFactory<?, ?> o, final int n) {
6056
if (n < 0 || n > 1)
6157
throw new IndexOutOfBoundsException();
6258

63-
Type elementType = typeService.reify(o.getValue());
59+
Type elementType = t.reify(o.getValue());
6460
if (n == 0)
6561
return elementType;
6662
// if we need the second type parameter, it can just be a

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,10 @@
3636
import net.imglib2.outofbounds.OutOfBoundsFactory;
3737

3838
import org.scijava.Priority;
39+
import org.scijava.plugin.Plugin;
3940
import org.scijava.types.Any;
4041
import org.scijava.types.TypeExtractor;
41-
import org.scijava.types.TypeService;
42-
import org.scijava.plugin.Parameter;
43-
import org.scijava.plugin.Plugin;
42+
import org.scijava.types.TypeReifier;
4443

4544
/**
4645
* {@link TypeExtractor} plugin which operates on {@link OutOfBoundsFactory} objects.
@@ -55,11 +54,8 @@
5554
@Plugin(type = TypeExtractor.class, priority = Priority.LOW_PRIORITY)
5655
public class OutOfBoundsFactoryTypeExtractor implements TypeExtractor<OutOfBoundsFactory<?, ?>> {
5756

58-
@Parameter
59-
private TypeService typeService;
60-
6157
@Override
62-
public Type reify(final OutOfBoundsFactory<?, ?> o, final int n) {
58+
public Type reify(final TypeReifier t, final OutOfBoundsFactory<?, ?> o, final int n) {
6359
if (n < 0 || n > 1) throw new IndexOutOfBoundsException();
6460

6561
return new Any();

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,10 @@
3838
import net.imglib2.outofbounds.OutOfBoundsConstantValueFactory;
3939
import net.imglib2.outofbounds.OutOfBoundsRandomValueFactory;
4040

41+
import org.scijava.plugin.Plugin;
4142
import org.scijava.types.Any;
4243
import org.scijava.types.TypeExtractor;
43-
import org.scijava.types.TypeService;
44-
import org.scijava.plugin.Parameter;
45-
import org.scijava.plugin.Plugin;
44+
import org.scijava.types.TypeReifier;
4645
import org.scijava.types.Types;
4746

4847
/**
@@ -54,11 +53,8 @@
5453
@Plugin(type = TypeExtractor.class)
5554
public class OutOfBoundsRandomValueFactoryTypeExtractor implements TypeExtractor<OutOfBoundsRandomValueFactory<?, ?>> {
5655

57-
@Parameter
58-
private TypeService typeService;
59-
6056
@Override
61-
public Type reify(final OutOfBoundsRandomValueFactory<?, ?> o, final int n) {
57+
public Type reify(final TypeReifier t, final OutOfBoundsRandomValueFactory<?, ?> o, final int n) {
6258
if (n < 0 || n > 1)
6359
throw new IndexOutOfBoundsException();
6460

@@ -70,7 +66,7 @@ public Type reify(final OutOfBoundsRandomValueFactory<?, ?> o, final int n) {
7066
} catch (Exception e) {
7167

7268
}
73-
Type elementType = typeService.reify(elementObject);
69+
Type elementType = t.reify(elementObject);
7470
if (n == 0)
7571
return elementType;
7672
// if we need the second type parameter, it can just be a

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,9 @@
3737
import net.imglib2.util.Util;
3838

3939
import org.scijava.Priority;
40-
import org.scijava.plugin.Parameter;
4140
import org.scijava.plugin.Plugin;
4241
import org.scijava.types.TypeExtractor;
43-
import org.scijava.types.TypeService;
42+
import org.scijava.types.TypeReifier;
4443

4544
/**
4645
* {@link TypeExtractor} plugin which operates on
@@ -57,15 +56,12 @@ public class RAITypeExtractor implements
5756
TypeExtractor<RandomAccessibleInterval<?>>
5857
{
5958

60-
@Parameter
61-
private TypeService typeService;
62-
6359
@Override
64-
public Type reify(final RandomAccessibleInterval<?> o, final int n) {
60+
public Type reify(final TypeReifier t, final RandomAccessibleInterval<?> o, final int n) {
6561
if (n != 0) throw new IndexOutOfBoundsException();
6662

6763
// type of the image
68-
Type raiType = typeService.reify(Util.getTypeFromInterval(o));
64+
Type raiType = t.reify(Util.getTypeFromInterval(o));
6965
return raiType;
7066
}
7167

scijava/scijava-ops-engine/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@
147147
<artifactId>scijava-discovery-therapi</artifactId>
148148
<version>${project.version}</version>
149149
</dependency>
150+
<dependency>
151+
<groupId>org.scijava</groupId>
152+
<artifactId>scijava-log2</artifactId>
153+
<version>${project.version}</version>
154+
</dependency>
150155
<dependency>
151156
<groupId>org.scijava</groupId>
152157
<artifactId>scijava-ops-serviceloader</artifactId>

0 commit comments

Comments
 (0)