Skip to content

Commit fc39f1b

Browse files
authored
Merge pull request #264 from scijava/scijava-ops-indexer/expose-implNote-hints
Expose Hints via Javadoc
2 parents fe24f23 + 5dd7710 commit fc39f1b

8 files changed

Lines changed: 44 additions & 9 deletions

File tree

docs/environment.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
name: scijava-docs
22
channels:
33
- conda-forge
4-
- defaults
54
dependencies:
65
- myst-nb
76
- openjdk=11

docs/ops/doc/WritingYourOwnOpPackage.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ Assuming your project is following Maven's [standard directory layout](https://m
467467
```yaml
468468
- op:
469469
names: [your.op.name1, your.op.name2, ...] # Array of Strings
470+
hints: [op.hint1, op.hint2, ...] # Array of Strings
470471
description: 'your Op description' # String
471472
source: yourOpSource # String - see below
472473
priority: 0.0 # Number
@@ -493,6 +494,17 @@ Assuming your project is following Maven's [standard directory layout](https://m
493494
494495
Of particular note are the following sections:
495496
497+
#### Hints
498+
499+
Each Op can define a set of hints (i.e. flags to the matcher) that can enable/disable particular aspects of the matcher.
500+
501+
Some of the most useful Op hints are described below:
502+
503+
| Hint | Use Case |
504+
|------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
505+
| `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. |
506+
| `Conversion.FORBIDDEN` | `engine.convert` Ops often require this hint to avoid infinite loops in <br>converted Op matching. |
507+
496508
#### Source
497509
498510
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:

scijava-ops-api/src/main/java/org/scijava/ops/api/Hints.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public Hints(final String... startingHints) {
6262
this(Arrays.asList(startingHints));
6363
}
6464

65-
private Hints(final Collection<String> hints) {
65+
public Hints(final Collection<String> hints) {
6666
this.hints = new HashSet<>(hints);
6767
}
6868

scijava-ops-engine/src/main/java/org/scijava/ops/engine/yaml/impl/AbstractYAMLOpInfo.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
import org.scijava.priority.Priority;
3636
import org.scijava.struct.Struct;
3737

38-
import java.lang.reflect.Type;
3938
import java.util.ArrayList;
39+
import java.util.Collections;
4040
import java.util.List;
4141
import java.util.Map;
4242

@@ -59,7 +59,10 @@ public AbstractYAMLOpInfo(final Map<String, Object> yaml,
5959
this.priority = parsePriority();
6060
this.description = yaml.getOrDefault("description", "").toString();
6161
this.version = (String) yaml.get("version");
62-
this.hints = new Hints();
62+
this.hints = new Hints((List<String>) yaml.getOrDefault( //
63+
"hints", //
64+
Collections.emptyList() //
65+
));
6366
}
6467

6568
/**

scijava-ops-engine/src/test/java/org/scijava/ops/engine/yaml/impl/YAMLOpTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,16 @@ public void testYAMLDescription() {
121121
Assertions.assertEquals(expected, actual);
122122
}
123123

124+
@Test
125+
public void testYAMLHints() {
126+
var infos = ops.infos("example.xor");
127+
Assertions.assertEquals(1, infos.size());
128+
var info = infos.iterator().next();
129+
var hints = info.declaredHints();
130+
Assertions.assertTrue(hints.containsAll( //
131+
"Adaptation.FORBIDDEN", //
132+
"Conversion.FORBIDDEN" //
133+
));
134+
}
135+
124136
}

scijava-ops-engine/src/test/java/org/scijava/ops/engine/yaml/impl/ops/YAMLMethodOp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static <N extends Number> Double subtract(N aDouble, N aDouble2) {
5757
/**
5858
* Another example Op, implemented by a {@link Method}
5959
*
60-
* @implNote op name=example.xor, type=Inplace1
60+
* @implNote op name=example.xor, type=Inplace1, hints="Adaptation.FORBIDDEN,Conversion.FORBIDDEN"
6161
* @param aList the first integer {@link List}
6262
* @param aList2 the second integer {@link List}
6363
*/

scijava-ops-indexer/src/main/java/org/scijava/ops/indexer/OpImplData.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,15 @@
2929

3030
package org.scijava.ops.indexer;
3131

32-
import static org.scijava.ops.indexer.ProcessingUtils.blockSeparator;
33-
import static org.scijava.ops.indexer.ProcessingUtils.tagElementSeparator;
34-
3532
import java.net.URI;
3633
import java.util.*;
3734
import java.util.stream.Collectors;
3835

3936
import javax.annotation.processing.ProcessingEnvironment;
4037
import javax.lang.model.element.Element;
4138

39+
import static org.scijava.ops.indexer.ProcessingUtils.*;
40+
4241
/**
4342
* A data structure containing all the metadata needed to define an Op
4443
*
@@ -89,6 +88,11 @@ abstract class OpImplData {
8988
*/
9089
protected final List<String> authors = new ArrayList<>();
9190

91+
/**
92+
* A {@link List} of the hints declared by this Op
93+
*/
94+
protected final List<String> hints = new ArrayList<>();
95+
9296
protected final ProcessingEnvironment env;
9397

9498
/**
@@ -186,6 +190,10 @@ private void parseImplNote(String implTag) {
186190
else if ("names".equals(kv[0]) || "name".equals(kv[0])) {
187191
names.addAll(Arrays.asList(value.split("\\s*,\\s*")));
188192
}
193+
else if ("hints".equals(kv[0])) {
194+
195+
hints.addAll(Arrays.asList(value.split("\\s*,\\s*")));
196+
}
189197
else {
190198
if (value.contains(",")) {
191199
tags.put(kv[0], value.split(","));
@@ -216,6 +224,7 @@ public Map<String, Object> dumpData() {
216224
map.put("description", description);
217225
map.put("priority", priority);
218226
map.put("authors", authors.toArray(String[]::new));
227+
map.put("hints", hints.toArray(String[]::new));
219228
var foo = params.stream() //
220229
.map(OpParameter::data) //
221230
.collect(Collectors.toList());

scijava-ops-indexer/src/main/java/org/scijava/ops/indexer/ProcessingUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ final class ProcessingUtils {
6565
* tags.
6666
*/
6767
public static final Pattern tagElementSeparator = Pattern.compile(
68-
"\\s*[,\\s]+(?=(?:[^']*'[^']*')*[^']*$)");
68+
"\\s*[,\\s]+(?=(?:[^'\"]*['\"][^'\"]*['\"])*[^'\"]*$)");
6969

7070
private ProcessingUtils() {
7171
throw new AssertionError("not instantiable");

0 commit comments

Comments
 (0)