Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion docs/environment.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: scijava-docs
channels:
- conda-forge
- defaults
dependencies:
- myst-nb
- openjdk=11
Expand Down
12 changes: 12 additions & 0 deletions docs/ops/doc/WritingYourOwnOpPackage.md
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,7 @@ Assuming your project is following Maven's [standard directory layout](https://m
```yaml
- op:
names: [your.op.name1, your.op.name2, ...] # Array of Strings
hints: [op.hint1, op.hint2, ...] # Array of Strings
description: 'your Op description' # String
source: yourOpSource # String - see below
priority: 0.0 # Number
Expand All @@ -493,6 +494,17 @@ Assuming your project is following Maven's [standard directory layout](https://m

Of particular note are the following sections:

#### Hints

Each Op can define a set of hints (i.e. flags to the matcher) that can enable/disable particular aspects of the matcher.

Some of the most useful Op hints are described below:

| Hint | Use Case |
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Adaptation.FORBIDDEN` | Some algorithms like a [Fast Fourier Transform](https://en.wikipedia.org/wiki/Fast_Fourier_transform) require their outputs be <br>of a particular size (not equivalent to the input size). If they are a `Computer`, <br>adaptation to `Function`s may cause errors. |
| `Conversion.FORBIDDEN` | `engine.convert` Ops often require this hint to avoid infinite loops in <br>converted Op matching. |

#### Source

For **java objects**, the `source` will start with one of the following prefix, followed by a `:/`, followed by a [percent-encoded](https://developer.mozilla.org/en-US/docs/Glossary/Percent-encoding) stringification of the Op (i.e. calling `toString()` on the object). Examples are shown below:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Hints(final String... startingHints) {
this(Arrays.asList(startingHints));
}

private Hints(final Collection<String> hints) {
public Hints(final Collection<String> hints) {
this.hints = new HashSet<>(hints);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
import org.scijava.priority.Priority;
import org.scijava.struct.Struct;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

Expand All @@ -59,7 +59,10 @@ public AbstractYAMLOpInfo(final Map<String, Object> yaml,
this.priority = parsePriority();
this.description = yaml.getOrDefault("description", "").toString();
this.version = (String) yaml.get("version");
this.hints = new Hints();
this.hints = new Hints((List<String>) yaml.getOrDefault( //
"hints", //
Collections.emptyList() //
));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,16 @@ public void testYAMLDescription() {
Assertions.assertEquals(expected, actual);
}

@Test
public void testYAMLHints() {
var infos = ops.infos("example.xor");
Assertions.assertEquals(1, infos.size());
var info = infos.iterator().next();
var hints = info.declaredHints();
Assertions.assertTrue(hints.containsAll( //
"Adaptation.FORBIDDEN", //
"Conversion.FORBIDDEN" //
));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static <N extends Number> Double subtract(N aDouble, N aDouble2) {
/**
* Another example Op, implemented by a {@link Method}
*
* @implNote op name=example.xor, type=Inplace1
* @implNote op name=example.xor, type=Inplace1, hints="Adaptation.FORBIDDEN,Conversion.FORBIDDEN"
* @param aList the first integer {@link List}
* @param aList2 the second integer {@link List}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,15 @@

package org.scijava.ops.indexer;

import static org.scijava.ops.indexer.ProcessingUtils.blockSeparator;
import static org.scijava.ops.indexer.ProcessingUtils.tagElementSeparator;

import java.net.URI;
import java.util.*;
import java.util.stream.Collectors;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.Element;

import static org.scijava.ops.indexer.ProcessingUtils.*;

/**
* A data structure containing all the metadata needed to define an Op
*
Expand Down Expand Up @@ -89,6 +88,11 @@ abstract class OpImplData {
*/
protected final List<String> authors = new ArrayList<>();

/**
* A {@link List} of the hints declared by this Op
*/
protected final List<String> hints = new ArrayList<>();

protected final ProcessingEnvironment env;

/**
Expand Down Expand Up @@ -186,6 +190,10 @@ private void parseImplNote(String implTag) {
else if ("names".equals(kv[0]) || "name".equals(kv[0])) {
names.addAll(Arrays.asList(value.split("\\s*,\\s*")));
}
else if ("hints".equals(kv[0])) {

hints.addAll(Arrays.asList(value.split("\\s*,\\s*")));
}
else {
if (value.contains(",")) {
tags.put(kv[0], value.split(","));
Expand Down Expand Up @@ -216,6 +224,7 @@ public Map<String, Object> dumpData() {
map.put("description", description);
map.put("priority", priority);
map.put("authors", authors.toArray(String[]::new));
map.put("hints", hints.toArray(String[]::new));
var foo = params.stream() //
.map(OpParameter::data) //
.collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ final class ProcessingUtils {
* tags.
*/
public static final Pattern tagElementSeparator = Pattern.compile(
"\\s*[,\\s]+(?=(?:[^']*'[^']*')*[^']*$)");
"\\s*[,\\s]+(?=(?:[^'\"]*['\"][^'\"]*['\"])*[^'\"]*$)");

private ProcessingUtils() {
throw new AssertionError("not instantiable");
Expand Down