Skip to content

Commit 13ba815

Browse files
Treiblesschorlegselzer
authored andcommitted
Improve toString
1 parent 8f603c4 commit 13ba815

2 files changed

Lines changed: 19 additions & 33 deletions

File tree

‎src/main/java/org/scijava/ops/OpUtils.java‎

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -272,9 +272,12 @@ public static String matchInfo(final MatchingResult res) {
272272
// fail, with information about the request and candidates
273273
sb.append("\n");
274274
sb.append("Request:\n");
275-
sb.append("-\t" + opString(ref.getLabel(), ref.getArgs()) + "\n");
275+
sb.append("-\t" + ref.toString() + "\n");
276276
sb.append("\n");
277277
sb.append("Candidates:\n");
278+
if (candidates.isEmpty()) {
279+
sb.append("-\t No candidates found!");
280+
}
278281
int count = 0;
279282
for (final OpCandidate candidate : candidates) {
280283
sb.append(++count + ". ");
@@ -294,36 +297,6 @@ public static String matchInfo(final MatchingResult res) {
294297
return sb.toString();
295298
}
296299

297-
/**
298-
* Gets a string describing the given op request.
299-
*
300-
* @param name
301-
* The op's name.
302-
* @param args
303-
* The op's input arguments.
304-
* @return A string describing the op request.
305-
*/
306-
public static String opString(final String name, final Type... args) {
307-
// TODO: add description of outputs
308-
final StringBuilder sb = new StringBuilder();
309-
sb.append(name + "(\n\t\t");
310-
boolean first = true;
311-
for (final Type arg : args) {
312-
if (first)
313-
first = false;
314-
else
315-
sb.append(",\n\t\t");
316-
if (arg == null)
317-
sb.append("null");
318-
else {
319-
// NB: Class instance used to mark argument type.
320-
sb.append(arg.getTypeName());
321-
}
322-
}
323-
sb.append(")");
324-
return sb.toString();
325-
}
326-
327300
/**
328301
* Gets a string describing the given op, highlighting the specific
329302
* parameter.

‎src/main/java/org/scijava/ops/matcher/OpRef.java‎

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,21 @@ public boolean typesMatch(final Type opType) {
157157

158158
@Override
159159
public String toString() {
160-
String n = name == null ? "" : "Name: \"" + name + "\" ";
161-
return n + Arrays.deepToString(types);
160+
String n = name == null ? "" : "Name: \"" + name + "\", Types: ";
161+
n += Arrays.deepToString(types) + "\n";
162+
n += "Input Types: \n";
163+
for (Type arg : args) {
164+
n += "\t\t* ";
165+
n += arg.getTypeName();
166+
n += "\n";
167+
}
168+
n += "Output Types: \n";
169+
for (Type out : outTypes) {
170+
n += "\t\t* ";
171+
n += out.getTypeName();
172+
n += "\n";
173+
}
174+
return n.substring(0, n.length() - 1);
162175
}
163176

164177
@Override

0 commit comments

Comments
 (0)