Skip to content

Commit 1cedfe0

Browse files
committed
Convert symbols to annotation-like strings
1 parent e5bdf3e commit 1cedfe0

6 files changed

Lines changed: 21 additions & 41 deletions

File tree

scijava-ops-engine/src/main/java/org/scijava/ops/engine/matcher/simplify/SimplifiedOpDescriptionGenerator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,7 @@ private String buildOpString(Collection<OpInfo> infos, OpRequest req,
8585
.distinct() //
8686
.collect(Collectors.joining("\n\t- "));
8787
if (opString.isEmpty()) return "No Ops found matching this request.";
88-
var key = "Key: *=container, ^=mutable";
89-
return req.getName() + ":\n\t- " + opString + "\n" + key;
88+
return req.getName() + ":\n\t- " + opString;
9089
}
9190

9291
/**

scijava-ops-engine/src/main/java/org/scijava/ops/engine/util/Infos.java

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -281,41 +281,27 @@ private static String description(final OpInfo info, final String name, final Me
281281
public static String describeMultiLine(final OpInfo info) {
282282
final StringBuilder sb = new StringBuilder(info.implementationName());
283283
// Step 2: Inputs
284-
String key;
285284
for (var member: info.inputs()) {
286285
sb.append("\n\t");
287-
switch (member.getIOType()) {
288-
case INPUT:
289-
key = member.getKey();
290-
break;
291-
case MUTABLE:
292-
key = "^" + member.getKey();
293-
break;
294-
case CONTAINER:
295-
key = "*" + member.getKey();
296-
break;
297-
default:
298-
throw new IllegalArgumentException("Invalid IO type: " + member.getIOType());
299-
}
300-
sb.append("> ").append(key) //
286+
sb.append("> ").append(member.getKey()) //
301287
.append(member.isRequired() ? "" : " (optional)") //
302-
.append(" : ") //
303-
.append(typeString(member.getType(), true)); //
288+
.append(" : ");
289+
if (member.getIOType() == ItemIO.CONTAINER) {
290+
sb.append("@CONTAINER ");
291+
}
292+
else if (member.getIOType() == ItemIO.MUTABLE) {
293+
sb.append("@MUTABLE ");
294+
}
295+
296+
sb.append(typeString(member.getType(), true)); //
304297
if (!member.getDescription().isBlank()) {
305298
sb.append("\n\t\t").append(member.getDescription().replaceAll("\n\\s*", "\n\t\t"));
306299
}
307300
}
308301
// Step 3: Output
309302
Member<?> output = info.output();
310-
switch (output.getIOType()) {
311-
case OUTPUT:
303+
if (output.getIOType() == ItemIO.OUTPUT) {
312304
sb.append("\n\tReturns : ").append(typeString(output.getType(), true));
313-
break;
314-
case MUTABLE:
315-
case CONTAINER:
316-
break;
317-
default:
318-
throw new IllegalArgumentException("Invalid IO type: " + output.getIOType());
319305
}
320306
return sb.toString();
321307
}
@@ -330,10 +316,10 @@ public static String describeOneLine(final OpInfo info) {
330316
str += member.getKey();
331317
break;
332318
case MUTABLE:
333-
str += "^" + member.getKey();
319+
str += "@MUTABLE " + member.getKey();
334320
break;
335321
case CONTAINER:
336-
str += "*" + member.getKey();
322+
str += "@CONTAINER " + member.getKey();
337323
break;
338324
default:
339325
throw new IllegalArgumentException("Invalid IO type: " + member.getIOType());
@@ -353,12 +339,8 @@ public static String describeOneLine(final OpInfo info) {
353339
sb.append(typeString(output.getType(), false));
354340
break;
355341
case MUTABLE:
356-
sb.append("None");
357-
// sb.append("None [Overwrites MUTABLE]");
358-
break;
359342
case CONTAINER:
360343
sb.append("None");
361-
// sb.append("None [Fills CONTAINER]");
362344
break;
363345
default:
364346
throw new IllegalArgumentException("Invalid IO type: " + output.getIOType());

scijava-ops-engine/src/test/java/org/scijava/ops/engine/OpEnvironmentTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public void testHelpVerboseOp() {
109109

110110
// Get the Op matching the description
111111
String descriptions = helpEnv.helpVerbose("help.verbose1");
112-
String expected = "help.verbose1:\n\t- org.scijava.ops.engine.OpifyOp1\n\t\tReturns : java.lang.String\nKey: *=container, ^=mutable";
112+
String expected = "help.verbose1:\n\t- org.scijava.ops.engine.OpifyOp1\n\t\tReturns : java.lang.String";
113113
Assertions.assertEquals(expected, descriptions);
114114
}
115115

@@ -131,7 +131,7 @@ public void testInternalNamespaceHelp() {
131131
Assertions.assertEquals(expected, actual);
132132
// ...but make sure that if we really need help with the internal namespace, we can get it
133133
actual = helpEnv.help("engine.adapt");
134-
expected = "engine.adapt:\n\t- () -> String\nKey: *=container, ^=mutable";
134+
expected = "engine.adapt:\n\t- () -> String";
135135
Assertions.assertEquals(expected, actual);
136136
}
137137

scijava-ops-engine/src/test/java/org/scijava/ops/engine/matcher/simplify/SimplifiedOpInfoTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,17 @@ public void testSimpleDescriptions() {
125125
String expected = "test.coalesceSimpleDescription:\n" +
126126
"\t- org.scijava.ops.engine.matcher.simplify.SimplifiedOpInfoTest$comp1\n" +
127127
"\t\t> input1 : java.util.List<java.lang.Long>\n" +
128-
"\t\t> *container1 : java.util.List<java.lang.Long>\n" +
128+
"\t\t> container1 : @CONTAINER java.util.List<java.lang.Long>\n" +
129129
"\t- org.scijava.ops.engine.matcher.simplify.SimplifiedOpInfoTest$func1\n" +
130130
"\t\t> input1 : java.lang.Double\n" + "\t\tReturns : java.lang.Double\n" +
131131
"\t- org.scijava.ops.engine.matcher.simplify.SimplifiedOpInfoTest$func2\n" +
132-
"\t\t> input1 : java.lang.Long\n" + "\t\tReturns : java.lang.Long\n" +
133-
"Key: *=container, ^=mutable";
132+
"\t\t> input1 : java.lang.Long\n" + "\t\tReturns : java.lang.Long";
134133

135134
Assertions.assertEquals(expected, actual);
136135

137136
actual = ops.unary("test.coalesceSimpleDescription").help();
138137
expected = //
139-
"test.coalesceSimpleDescription:\n\t- (input1, *container1) -> None\n\t- (input1) -> Number\nKey: *=container, ^=mutable";
138+
"test.coalesceSimpleDescription:\n\t- (input1, @CONTAINER container1) -> None\n\t- (input1) -> Number";
140139
Assertions.assertEquals(expected, actual);
141140
// Finally test that different number of outputs doesn't retrieve the Ops
142141
actual = ops.nullary("test.coalesceSimpleDescription").help();

scijava-ops-engine/src/test/java/org/scijava/ops/engine/util/InfosTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public static Integer nullableMethod(Integer i1, @Nullable Integer i2) {
3131
@Test
3232
public void testDescriptionOfNullableParameter() {
3333
var actual = ops.help("test.nullableMethod");
34-
var expected = "test.nullableMethod:\n\t- (input1, input2 = null) -> Integer\nKey: *=container, ^=mutable";
34+
var expected = "test.nullableMethod:\n\t- (input1, input2 = null) -> Integer";
3535
Assertions.assertEquals(expected, actual);
3636
}
3737
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public void testYAMLField() {
102102
@Test
103103
public void testYAMLDescription() {
104104
var actual = ops.help("example.mul");
105-
var expected = "example.mul:\n\t- (a, b) -> Double\nKey: *=container, ^=mutable";
105+
var expected = "example.mul:\n\t- (a, b) -> Double";
106106
Assertions.assertEquals(expected, actual);
107107
}
108108

0 commit comments

Comments
 (0)