Skip to content

Commit 44348e9

Browse files
committed
ValidityProblem -> InvalidOpException subclasses
1 parent ebc55de commit 44348e9

49 files changed

Lines changed: 692 additions & 505 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/net/imagej/ops2/threshold/ApplyLocalThresholdIntegral.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
import java.util.List;
3434
import java.util.function.Function;
3535

36+
import org.scijava.function.Computers;
37+
import org.scijava.ops.spi.OpDependency;
38+
import org.scijava.ops.spi.OpExecutionException;
39+
3640
import net.imagej.ops2.stats.IntegralMean;
3741
import net.imglib2.FinalInterval;
3842
import net.imglib2.RandomAccessibleInterval;
@@ -52,10 +56,6 @@
5256
import net.imglib2.view.Views;
5357
import net.imglib2.view.composite.Composite;
5458

55-
import org.scijava.function.Computers;
56-
import org.scijava.ops.spi.OpExecutionException;
57-
import org.scijava.ops.spi.OpDependency;
58-
5959
/**
6060
* Apply a local thresholding method to an image using integral images for speed
6161
* up, optionally using an out of bounds strategy.

imagej/imagej-ops2/src/test/java/net/imagej/ops2/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class OpRegressionTest extends AbstractOpTest {
3939

4040
@Test
4141
public void opDiscoveryRegressionIT() {
42-
long expected = 1463;
42+
long expected = 1464;
4343
long actual = ops.infos().size();
4444
assertEquals(expected, actual);
4545
}

scijava/scijava-ops-engine/src/main/java/module-info.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
*/
1212

1313
exports org.scijava.ops.engine;
14-
exports org.scijava.ops.engine.matcher;
1514
exports org.scijava.ops.engine.conversionLoss;
1615
exports org.scijava.ops.engine.util;
1716

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
package org.scijava.ops.engine.exceptions;
3+
4+
import org.scijava.ops.api.OpEnvironment;
5+
import org.scijava.ops.spi.Op;
6+
7+
/**
8+
* {@link Exception} denoting that an {@link Op} implementation could not be
9+
* accepted into an {@link OpEnvironment} because of invalid parameters or
10+
* configuration.
11+
*
12+
* @author Gabriel Selzer
13+
*/
14+
public abstract class InvalidOpException extends RuntimeException {
15+
16+
public InvalidOpException(final String message) {
17+
super(message);
18+
}
19+
20+
public InvalidOpException(final Throwable cause) {
21+
super(cause);
22+
}
23+
24+
public InvalidOpException(final String message, final Throwable cause) {
25+
super(message, cause);
26+
}
27+
28+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import java.lang.reflect.Field;
5+
6+
import org.scijava.ops.api.OpEnvironment;
7+
import org.scijava.ops.engine.exceptions.InvalidOpException;
8+
import org.scijava.ops.spi.OpDependency;
9+
10+
/**
11+
* Exception thrown when an Op has a {@link Field} {@link OpDependency} that is
12+
* {@code final}. This is not allowed as the {@link OpEnvironment} must inject
13+
* the {@link OpDependency} at runtime, after instantiation.
14+
*
15+
* @author Gabriel Selzer
16+
*/
17+
public class FinalOpDependencyFieldException extends InvalidOpException {
18+
19+
public FinalOpDependencyFieldException(final Field f) {
20+
super("Invalid Op dependency: Field dependency " + f.getName() + " of Op " +
21+
f.getDeclaringClass() + " cannot be final!");
22+
}
23+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import java.lang.reflect.Method;
5+
import java.lang.reflect.Type;
6+
7+
import org.scijava.ops.engine.exceptions.InvalidOpException;
8+
9+
/**
10+
* Exception thrown when an Op written as a {@link Method} does not conform to a
11+
* functional {@link Type} (i.e. implementing an interface with a single
12+
* abstract {@link Method}). This is not allowed, as if there are multiple
13+
* methods, Ops will not know which method to call!
14+
*
15+
* @author Gabriel Selzer
16+
*/
17+
public class FunctionalTypeOpException extends InvalidOpException {
18+
19+
/**
20+
* Standard constructor.
21+
*
22+
* @param op An Op implementation
23+
* @param fIface the {@link FunctionalInterface} that the Op should conform
24+
* to.
25+
*/
26+
public FunctionalTypeOpException(final Object op, final Type fIface) {
27+
super("The signature of method " + op +
28+
" does not conform to the op type " + fIface);
29+
}
30+
31+
/**
32+
* Constructor used when another {@link Exception} indicates an issue with the
33+
* functional type
34+
*
35+
* @param op An Op implementation
36+
* @param cause the {@link Throwable} identifying a bad Op type.
37+
*/
38+
public FunctionalTypeOpException(final Object op, final Throwable cause) {
39+
super("The signature of op " + op + " did not have a suitable Op type.",
40+
cause);
41+
}
42+
43+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import java.lang.reflect.Method;
5+
6+
import org.scijava.ops.engine.exceptions.InvalidOpException;
7+
8+
/**
9+
* Exception thrown when an Op declared as a {@link Method} is an instance
10+
* method of some class. This is not allowed, as the Op engine doesn't know how
11+
* to instantiate the declaring class of an instance method.
12+
*
13+
* @author Gabriel Selzer
14+
*/
15+
public class InstanceOpMethodException extends InvalidOpException {
16+
17+
/**
18+
* Default constructor
19+
*
20+
* @param method the instance method
21+
*/
22+
public InstanceOpMethodException(final Method method) {
23+
super("Method " + method + " must be static");
24+
}
25+
26+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import org.scijava.ops.engine.exceptions.InvalidOpException;
5+
6+
/**
7+
* An {@link InvalidOpException} arising when an Op declares multiple outputs.
8+
* This is not allowed as an Op, by definition, can only have one output.
9+
*
10+
* @author Gabriel Selzer
11+
*/
12+
public class MultipleOutputsOpException extends InvalidOpException {
13+
14+
public MultipleOutputsOpException(Object op) {
15+
super("Multiple output parameters specified for Op " + op +
16+
" - Only a single output is allowed.");
17+
}
18+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import java.lang.reflect.Method;
5+
import java.util.List;
6+
7+
import org.scijava.ops.engine.exceptions.InvalidOpException;
8+
import org.scijava.ops.spi.Nullable;
9+
10+
/**
11+
* Exception thrown when an Op declares {@link Nullable} parameters in multiple
12+
* places (i.e. both on the implementation method and on an abstract interface
13+
* method). This is not allowed to avoid action-at-a-distance errors.
14+
*
15+
* @author Gabriel Selzer
16+
*/
17+
public class NullablesOnMultipleMethodsException extends InvalidOpException {
18+
19+
public NullablesOnMultipleMethodsException(final Object source,
20+
final List<Method> functionalMethodsWithNullables)
21+
{
22+
super("Only one method in the hierarchy of Op " + source +
23+
" can declare @Nullable parameters, however this Op has multiple: " +
24+
functionalMethodsWithNullables);
25+
}
26+
27+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
package org.scijava.ops.engine.exceptions.impl;
3+
4+
import java.lang.reflect.Method;
5+
6+
import org.scijava.ops.engine.exceptions.InvalidOpException;
7+
8+
/**
9+
* Exception thrown when an Op written as a {@link Method} declares an
10+
* {@link org.scijava.ops.spi.OpDependency} <b>after</b> an Op parameter. All
11+
* {@link org.scijava.ops.spi.OpDependency} parameters must come before any Op
12+
* parameters.
13+
*
14+
* @author Gabriel Selzer
15+
*/
16+
public class OpDependencyPositionException extends InvalidOpException {
17+
18+
public OpDependencyPositionException(final Method opMethod) {
19+
super("Op Dependencies in Op method " + opMethod +
20+
" must come before any other parameters!");
21+
}
22+
23+
}

0 commit comments

Comments
 (0)