Skip to content
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
</dependency>

<dependency>
<groupId>io.leangen.geantyref</groupId>
<artifactId>geantyref</artifactId>
<version>1.3.6</version>
</dependency>

<!-- Test scope dependencies -->
<dependency>
Expand Down
116 changes: 58 additions & 58 deletions src/main/java/net/imagej/ops/transform/Transforms.java

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/main/java/org/scijava/ops/OpService.java
Original file line number Diff line number Diff line change
Expand Up @@ -292,15 +292,15 @@ private Type[] toTypes(Nil<?>... nils) {
* OutputTypes: [Double[]]
* </pre>
* Input and output types will be inferred by looking at the signature of the functional
* method of the specified type. Also see {@link ParameterStructs#getFunctionalMethodTypes(Type)}.
* method of the specified type. Also see {@link ParameterStructs#findFunctionalMethodTypes(Type)}.
*
* @param type
* @param name
* @return null if
* the specified type has no functional method
*/
private OpRef inferOpRef(Type type, String name) {
List<FunctionalMethodType> fmts = ParameterStructs.getFunctionalMethodTypes(type);
List<FunctionalMethodType> fmts = ParameterStructs.findFunctionalMethodTypes(type);
if (fmts == null) return null;

EnumSet<ItemIO> inIos = EnumSet.of(ItemIO.BOTH, ItemIO.INPUT);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/ops/copy/CopyOpCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class CopyOpCollection {

@OpField(names = "cp, copy", priority = Priority.LOW)
@Parameter(key = "array")
@Parameter(key = "arrayCopy", type = ItemIO.BOTH)
@Parameter(key = "arrayCopy", itemIO = ItemIO.BOTH)
public static final Computer<double[], double[]> copyPrimitiveDoubleArray = (from, to) -> {
for (int i = 0; i < to.length; i++) {
to[i] = from[i];
Expand All @@ -22,7 +22,7 @@ public class CopyOpCollection {

@OpField(names = "cp, copy", priority = Priority.LOW)
@Parameter(key = "array")
@Parameter(key = "arrayCopy", type = ItemIO.BOTH)
@Parameter(key = "arrayCopy", itemIO = ItemIO.BOTH)
public static final Computer<Double[], Double[]> copyDoubleArray = (from, to) -> {
for (int i = 0; i < to.length; i++) {
to[i] = from[i];
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/ops/core/OneToOneCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

public abstract class OneToOneCommand<I, O> implements Command, Supplier<O> {

@Parameter
@Parameter(itemIO=ItemIO.INPUT)
protected I input;

@Parameter(type = ItemIO.OUTPUT)
@Parameter(itemIO = ItemIO.OUTPUT)
protected O output;

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/scijava/ops/create/CreateOpCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public class CreateOpCollection {

@OpField(names = "create, src, source", priority = Priority.LOW)
@Parameter(key = "array")
@Parameter(key = "arrayLike", type = ItemIO.OUTPUT)
@Parameter(key = "arrayLike", itemIO = ItemIO.OUTPUT)
public static final Function<double[], double[]> createDoubleArrayInputAware = from -> new double[from.length];

@OpField(names = "create, src, source", priority = Priority.LOW)
@Parameter(key = "array1")
@Parameter(key = "array2")
@Parameter(key = "arrayLike", type = ItemIO.OUTPUT)
@Parameter(key = "arrayLike", itemIO = ItemIO.OUTPUT)
public static final BiFunction<double[], double[], double[]> createDoubleArrayBiInputAware = (i1, i2) -> {
if (i1.length != i2.length) {
throw new IllegalArgumentException("Input array length muss be equal");
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scijava/ops/matcher/OpFieldInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public OpFieldInfo(final Field field) {
// ALLOWED!
this.field = field;
try {
struct = ParameterStructs.structOf(field.getDeclaringClass(), field);
struct = ParameterStructs.structOf(field);
if (!Modifier.isStatic(field.getModifiers())) {
instance = field.getDeclaringClass().newInstance();
}
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/scijava/ops/math/Add.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class Add {
@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
@Parameter(key = "result", itemIO = ItemIO.OUTPUT)
public static class MathAddDoublesFunction implements BiFunction<Double, Double, Double> {
@Override
public Double apply(Double t, Double u) {
Expand All @@ -50,7 +50,7 @@ public Double apply(Double t, Double u) {
@Plugin(type = Op.class, priority = Priority.HIGH, name = NAMES)
@Parameter(key = "iter1")
@Parameter(key = "iter2")
@Parameter(key = "resultArray", type = ItemIO.OUTPUT)
@Parameter(key = "resultArray", itemIO = ItemIO.OUTPUT)
public static class MathPointwiseAddIterablesFunction<M extends Number, I extends Iterable<M>>
implements BiFunction<I, I, Iterable<Double>> {
@Override
Expand All @@ -66,7 +66,7 @@ public Iterable<Double> apply(I i1, I i2) {
@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "integer1")
@Parameter(key = "integer2")
@Parameter(key = "resultInteger", type = ItemIO.OUTPUT)
@Parameter(key = "resultInteger", itemIO = ItemIO.OUTPUT)
public static class MathAddBigIntegersComputer implements BiFunction<BigInteger, BigInteger, BigInteger> {
@Override
public BigInteger apply(BigInteger t, BigInteger u) {
Expand All @@ -77,7 +77,7 @@ public BigInteger apply(BigInteger t, BigInteger u) {
@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "array1")
@Parameter(key = "array2")
@Parameter(key = "resultArray", type = ItemIO.BOTH)
@Parameter(key = "resultArray", itemIO = ItemIO.BOTH)
public static class MathPointwiseAddDoubleArraysComputer implements BiComputer<double[], double[], double[]> {
@Override
public void compute(double[] in1, double[] in2, double[] out) {
Expand All @@ -90,7 +90,7 @@ public void compute(double[] in1, double[] in2, double[] out) {
// --------- Inplaces ---------

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "arrayIO", type = ItemIO.BOTH)
@Parameter(key = "arrayIO", itemIO = ItemIO.BOTH)
@Parameter(key = "array1")
public static class MathPointwiseAddDoubleArraysInplace1 implements BiInplace1<double[], double[]> {
@Override
Expand Down
20 changes: 0 additions & 20 deletions src/main/java/org/scijava/ops/math/MathOpCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,23 @@
import org.scijava.plugin.Plugin;
import org.scijava.struct.ItemIO;

// TODO: Derive parameters from the one abstract method of the functional interface in question.
// This also will tell us the number of inputs vs. outputs. But!
// It will NOT tell us if an argument is "BOTH".
// And it will NOT tell us the preferred NAME of the argument.

@Plugin(type = OpCollection.class)
public class MathOpCollection {

@OpField(names = MathOps.ADD, priority = Priority.LOW)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
public static final BiFunction<Double, Double, Double> addDoublesFunction = (x, y) -> x + y;

// Set this priority to extremely high for now to test that the op with the highest priority is actually retrieved
@OpField(names = MathOps.ADD, priority = Priority.EXTREMELY_HIGH)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
public static final BinaryOperator<Double> addDoublesOperator = (x, y) -> x + y;

@OpField(names = MathOps.SUB)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
public static final BiFunction<Double, Double, Double> subDoublesFunction = (t, u) -> t - u;

@OpField(names = MathOps.MUL)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
public static final BiFunction<Double, Double, Double> mulDoublesFunction = (t, u) -> t * u;

@OpField(names = MathOps.DIV)
@Parameter(key = "number1")
@Parameter(key = "number2")
@Parameter(key = "result", type = ItemIO.OUTPUT)
public static final BiFunction<Double, Double, Double> divDoublesFunction = (t, u) -> t / u;

}
6 changes: 3 additions & 3 deletions src/main/java/org/scijava/ops/math/Normalize.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public class Normalize {

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "numbers")
@Parameter(key = "normalized", type = ItemIO.OUTPUT)
@Parameter(key = "normalized", itemIO = ItemIO.OUTPUT)
public static class MathMinMaxNormalizeFunction implements Function<double[], double[]> {

@Parameter
@Parameter(itemIO=ItemIO.INPUT)
private Double newMin;

@Parameter(required = false)
@Parameter(itemIO=ItemIO.INPUT, required = false)
private Double newMax;

@Override
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/scijava/ops/math/Power.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public class Power {

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "number")
@Parameter(key = "result", type = ItemIO.OUTPUT)
@Parameter(key = "result", itemIO = ItemIO.OUTPUT)
public static class MathPowerDoublConstantFunction implements Function<Double, Double> {

@Parameter
@Parameter(itemIO=ItemIO.INPUT)
private double exponent;

@Override
Expand All @@ -30,7 +30,7 @@ public Double apply(Double t) {
@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "number")
@Parameter(key = "exponent")
@Parameter(key = "result", type = ItemIO.OUTPUT)
@Parameter(key = "result", itemIO = ItemIO.OUTPUT)
public static class MathPowerDoubleFunction implements BiFunction<Double, Double, Double> {
@Override
public Double apply(Double t, Double exp) {
Expand All @@ -40,10 +40,10 @@ public Double apply(Double t, Double exp) {

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "array")
@Parameter(key = "resultArray", type = ItemIO.BOTH)
@Parameter(key = "resultArray", itemIO = ItemIO.BOTH)
public static class MathPointwisePowerDoubleArrayComputer implements Computer<double[], double[]> {

@Parameter
@Parameter(itemIO=ItemIO.INPUT)
private Double exponent;

@Override
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/scijava/ops/math/Sqrt.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Sqrt {

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "number1")
@Parameter(key = "result", type = ItemIO.OUTPUT)
@Parameter(key = "result", itemIO = ItemIO.OUTPUT)
public static class MathSqrtDoubleFunction implements Function<Double, Double> {
@Override
public Double apply(Double t) {
Expand All @@ -30,7 +30,7 @@ public Double apply(Double t) {

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "array1")
@Parameter(key = "resultArray", type = ItemIO.BOTH)
@Parameter(key = "resultArray", itemIO = ItemIO.BOTH)
public static class MathPointwiseSqrtDoubleArrayComputer implements Computer<double[], double[]> {
@Override
public void compute(double[] in1, double[] out) {
Expand All @@ -43,7 +43,7 @@ public void compute(double[] in1, double[] out) {
// --------- Inplaces ---------

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "arrayIO", type = ItemIO.BOTH)
@Parameter(key = "arrayIO", itemIO = ItemIO.BOTH)
public static class MathPointwiseSqrtDoubleArrayInplace implements Inplace<double[]> {
@Override
public void mutate(double[] in1) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/scijava/ops/math/Zero.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Zero {
// --------- Computers ---------

@Plugin(type = Op.class, name = NAMES)
@Parameter(key = "resultArray", type = ItemIO.BOTH)
@Parameter(key = "resultArray", itemIO = ItemIO.BOTH)
public static class MathParallelPointwiseZeroDoubleArrayComputer implements NullaryComputer<double[]> {
@Override
public void compute(double[] out) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public Type getType() {

@Override
public ItemIO getIOType() {
return getAnnotation().type();
return getAnnotation().itemIO();
}

@Override
Expand Down
17 changes: 12 additions & 5 deletions src/main/java/org/scijava/param/FieldParameterMember.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ public class FieldParameterMember<T> extends AnnotatedParameterMember<T>
private final Class<?> structType;
private final Struct struct;

public FieldParameterMember(final Field field, final Class<?> structType)
public FieldParameterMember(final Field field, final Class<?> structType, Parameter parameterAnnotation)
throws ValidityException
{
super(Types.fieldType(field, structType), //
field.getAnnotation(Parameter.class));
super(Types.fieldType(field, structType), parameterAnnotation);
this.field = field;
this.structType = structType;
struct = isStruct() ? ParameterStructs.structOf(getRawType()) : null;
Expand All @@ -46,7 +45,7 @@ public Field getField() {
public T get(final Object o) {
try {
@SuppressWarnings("unchecked")
final T value = (T) ParameterStructs.field(this).get(o);
final T value = (T) field(this).get(o);
return value;
}
catch (final IllegalAccessException exc) {
Expand All @@ -57,7 +56,7 @@ public T get(final Object o) {
@Override
public void set(final T value, final Object o) {
try {
ParameterStructs.field(this).set(o, value);
field(this).set(o, value);
}
catch (final IllegalAccessException exc) {
// FIXME
Expand Down Expand Up @@ -97,6 +96,14 @@ public T getDefaultValue() {
}

// -- Member methods --

public static <T> Field field(final Member<T> item) {
if (item instanceof FieldParameterMember) {
final FieldParameterMember<T> fpItem = (FieldParameterMember<T>) item;
return fpItem.getField();
}
return null;
}

@Override
public String getKey() {
Expand Down
30 changes: 16 additions & 14 deletions src/main/java/org/scijava/param/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,20 @@
@Repeatable(Parameters.class)
public @interface Parameter {

/**
* IMPORTANT: Parameter annotation instances are mutated using reflections
* in order to resolve {@link ItemIO#AUTO} which accesses this field
* by name. If the name is changed, this has to be changed accordingly.
*/
public static final String ITEMIO_FIELD_NAME = "itemIO";

/**
* IMPORTANT: Parameter annotation instances are mutated using reflections
* in order to resolve {@link ItemIO#AUTO} which accesses this field
* by name. If the name is changed, this has to be changed accordingly.
*/
public static final String KEY_FIELD_NAME = "key";

/** Defines a key for the parameter. */
String key() default "";

Expand All @@ -64,20 +78,8 @@
/** Defines a description for the parameter. */
String description() default "";

/**
* Defines the input/output type of the parameter.
* <p>
* Choices are:
* </p>
* <ul>
* <li>INPUT: parameter is an input for the plugin.</li>
* <li>OUTPUT: parameter is an output for the plugin.</li>
* <li>BOTH: parameter is both and input and an output for the plugin. This
* type is used to indicate an object that is mutated somehow during
* execution.</li>
* </ul>
*/
ItemIO type() default ItemIO.INPUT;
/** Defines the input/output type of the parameter See {@link ItemIO} */
ItemIO itemIO() default ItemIO.AUTO;

/**
* Defines whether the parameter references an object which itself has
Expand Down
Loading