Skip to content

Commit 487f192

Browse files
gselzerctrueden
authored andcommitted
Move OpCandidate to org.scijava.ops
1 parent 3c29298 commit 487f192

File tree

8 files changed

+85
-91
lines changed

8 files changed

+85
-91
lines changed

imagej/imagej-ops2/src/main/java/net/imagej/ops2/help/AbstractHelp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
import java.util.Iterator;
3434
import java.util.List;
3535

36+
import org.scijava.ops.OpCandidate;
3637
import org.scijava.ops.OpInfo;
3738
import org.scijava.ops.OpUtils;
38-
import org.scijava.ops.matcher.OpCandidate;
3939

4040
/**
4141
* Base class for help operations.

scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/OpCandidate.java renamed to scijava/scijava-ops/src/main/java/org/scijava/ops/OpCandidate.java

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,15 @@
2727
* #L%
2828
*/
2929

30-
package org.scijava.ops.matcher;
30+
package org.scijava.ops;
3131

3232
import java.lang.reflect.Type;
3333
import java.lang.reflect.TypeVariable;
3434
import java.util.List;
3535
import java.util.Map;
3636

3737
import org.scijava.log.Logger;
38-
import org.scijava.ops.OpEnvironment;
39-
import org.scijava.ops.OpInfo;
40-
import org.scijava.ops.OpRef;
41-
import org.scijava.ops.OpUtils;
38+
import org.scijava.ops.matcher.OpMatcher;
4239
import org.scijava.param.ValidityProblem;
4340
import org.scijava.struct.Member;
4441
import org.scijava.struct.Struct;
@@ -214,19 +211,18 @@ public String toString() {
214211
return info.toString();
215212
}
216213

217-
public StructInstance<?> createOpInstance(List<?> dependencies) throws OpMatchingException
214+
public StructInstance<?> createOpInstance(List<?> dependencies)
218215
{
219-
if (!getStatusCode().equals(StatusCode.MATCH)) {
220-
throw new OpMatchingException(
221-
"Status of candidate to create op from indicates a problem: " + getStatus());
216+
if (getStatusCode().equals(StatusCode.MATCH)) {
217+
return opInfo().createOpInstance(dependencies);
222218
}
223219

224-
StructInstance<?> inst = opInfo().createOpInstance(dependencies);
225-
return inst;
220+
throw new IllegalStateException(
221+
"Status of candidate to create op from indicates a problem: " +
222+
getStatus());
226223
}
227224

228225
public Object createOp(List<?> dependencies)
229-
throws OpMatchingException
230226
{
231227
return createOpInstance(dependencies).object();
232228
}

scijava/scijava-ops/src/main/java/org/scijava/ops/OpInfo.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.util.Map;
99

1010
import org.scijava.log.Logger;
11-
import org.scijava.ops.matcher.OpCandidate;
1211
import org.scijava.param.ValidityException;
1312
import org.scijava.struct.Member;
1413
import org.scijava.struct.Struct;

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

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@
3636
import java.util.Objects;
3737
import java.util.stream.Collectors;
3838

39-
import org.scijava.ops.matcher.MatchingResult;
40-
import org.scijava.ops.matcher.OpCandidate;
41-
import org.scijava.ops.matcher.OpCandidate.StatusCode;
42-
import org.scijava.ops.matcher.OpMatcher;
39+
import org.scijava.ops.OpCandidate.StatusCode;
4340
import org.scijava.param.ParameterMember;
4441
import org.scijava.param.ParameterStructs;
4542
import org.scijava.param.ValidityException;
@@ -255,11 +252,10 @@ public static List<Member<?>> injectableMembers(Struct struct) {
255252
* several matches that do not have equal output types, the output type may not
256253
* completely match the request as only raw type assignability will be checked
257254
* at the moment.
258-
* @see OpMatcher#typesMatch(OpCandidate)
259255
* @param matches
260256
* @return
261257
*/
262-
private static boolean typeCheckingIncomplete(List<OpCandidate> matches) {
258+
public static boolean typeCheckingIncomplete(List<OpCandidate> matches) {
263259
Type outputType = null;
264260
for (OpCandidate match : matches) {
265261
Type ts = output(match).getType();
@@ -277,72 +273,6 @@ public static Type[] getTypes(List<Member<?>> members) {
277273
return members.stream().map(m -> m.getType()).toArray(Type[]::new);
278274
}
279275

280-
/**
281-
* Gets a string with an analysis of a particular match request failure.
282-
* <p>
283-
* This method is used to generate informative exception messages when no
284-
* matches, or too many matches, are found.
285-
* </p>
286-
*
287-
* @param res
288-
* The result of type matching
289-
* @return A multi-line string describing the situation: 1) the type of
290-
* match failure; 2) the list of matching ops (if any); 3) the
291-
* request itself; and 4) the list of candidates including status
292-
* (i.e., whether it matched, and if not, why not).
293-
*/
294-
public static String matchInfo(final MatchingResult res) {
295-
final StringBuilder sb = new StringBuilder();
296-
297-
List<OpCandidate> candidates = res.getCandidates();
298-
List<OpCandidate> matches = res.getMatches();
299-
300-
final OpRef ref = res.getOriginalQueries().get(0);
301-
if (matches.isEmpty()) {
302-
// no matches
303-
sb.append("No matching '" + ref.getLabel() + "' op\n");
304-
} else {
305-
// multiple matches
306-
final double priority = getPriority(matches.get(0));
307-
sb.append("Multiple '" + ref.getLabel() + "' ops of priority " + priority + ":\n");
308-
if (typeCheckingIncomplete(matches)) {
309-
sb.append("Incomplete output type checking may have occured!\n");
310-
}
311-
int count = 0;
312-
for (final OpCandidate match : matches) {
313-
sb.append(++count + ". ");
314-
sb.append(match.toString() + "\n");
315-
}
316-
}
317-
318-
// fail, with information about the request and candidates
319-
sb.append("\n");
320-
sb.append("Request:\n");
321-
sb.append("-\t" + ref.toString() + "\n");
322-
sb.append("\n");
323-
sb.append("Candidates:\n");
324-
if (candidates.isEmpty()) {
325-
sb.append("-\t No candidates found!");
326-
}
327-
int count = 0;
328-
for (final OpCandidate candidate : candidates) {
329-
sb.append(++count + ". ");
330-
sb.append("\t" + opString(candidate.opInfo(), candidate.getStatusItem()) + "\n");
331-
final String status = candidate.getStatus();
332-
if (status != null)
333-
sb.append("\t" + status + "\n");
334-
if (candidate.getStatusCode() == StatusCode.DOES_NOT_CONFORM) {
335-
// TODO: Conformity not yet implemented
336-
// // show argument values when a contingent op rejects them
337-
// for (final ModuleItem<?> item : inputs(info)) {
338-
// final Object value = item.getValue(candidate.getModule());
339-
// sb.append("\t\t" + item.getName() + " = " + value + "\n");
340-
// }
341-
}
342-
}
343-
return sb.toString();
344-
}
345-
346276
public static String opString(final OpInfo info) {
347277
return opString(info, null);
348278
}

scijava/scijava-ops/src/main/java/org/scijava/ops/impl/DefaultOpEnvironment.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,10 @@
5656
import org.scijava.ops.BaseOpHints.Adaptation;
5757
import org.scijava.ops.BaseOpHints.DependencyMatching;
5858
import org.scijava.ops.BaseOpHints.Simplification;
59+
import org.scijava.ops.OpCandidate.StatusCode;
5960
import org.scijava.ops.Hints;
6061
import org.scijava.ops.Op;
62+
import org.scijava.ops.OpCandidate;
6163
import org.scijava.ops.OpCollection;
6264
import org.scijava.ops.OpDependency;
6365
import org.scijava.ops.OpDependencyMember;
@@ -76,8 +78,6 @@
7678
import org.scijava.ops.matcher.DependencyMatchingException;
7779
import org.scijava.ops.matcher.MatchingUtils;
7880
import org.scijava.ops.matcher.OpAdaptationInfo;
79-
import org.scijava.ops.matcher.OpCandidate;
80-
import org.scijava.ops.matcher.OpCandidate.StatusCode;
8181
import org.scijava.ops.matcher.OpClassInfo;
8282
import org.scijava.ops.matcher.OpFieldInfo;
8383
import org.scijava.ops.matcher.OpMatcher;

scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/DefaultOpMatcher.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@
4545

4646
import org.scijava.log.Logger;
4747
import org.scijava.ops.Hints;
48+
import org.scijava.ops.OpCandidate;
4849
import org.scijava.ops.OpEnvironment;
4950
import org.scijava.ops.OpInfo;
5051
import org.scijava.ops.OpRef;
5152
import org.scijava.ops.OpUtils;
5253
import org.scijava.ops.BaseOpHints.Simplification;
54+
import org.scijava.ops.OpCandidate.StatusCode;
5355
import org.scijava.ops.hint.DefaultHints;
54-
import org.scijava.ops.matcher.OpCandidate.StatusCode;
5556
import org.scijava.ops.simplify.InfoSimplificationGenerator;
5657
import org.scijava.service.AbstractService;
5758
import org.scijava.struct.Member;

scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/MatchingResult.java

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
import java.util.ArrayList;
44
import java.util.List;
55

6+
import org.scijava.ops.OpCandidate;
7+
import org.scijava.ops.OpCandidate.StatusCode;
68
import org.scijava.ops.OpRef;
79
import org.scijava.ops.OpUtils;
8-
import org.scijava.ops.simplify.SimplifiedOpInfo;
910

1011
/**
1112
* Class representing the result from type matching done by the
@@ -60,7 +61,73 @@ public OpCandidate singleMatch() {
6061
}
6162

6263
// There is no clear matching Op
63-
final String analysis = OpUtils.matchInfo(this);
64+
final String analysis = MatchingResult.matchInfo(this);
6465
throw new OpMatchingException(analysis);
6566
}
67+
68+
/**
69+
* Gets a string with an analysis of a particular match request failure.
70+
* <p>
71+
* This method is used to generate informative exception messages when no
72+
* matches, or too many matches, are found.
73+
* </p>
74+
*
75+
* @param res
76+
* The result of type matching
77+
* @return A multi-line string describing the situation: 1) the type of
78+
* match failure; 2) the list of matching ops (if any); 3) the
79+
* request itself; and 4) the list of candidates including status
80+
* (i.e., whether it matched, and if not, why not).
81+
*/
82+
public static String matchInfo(final MatchingResult res) {
83+
final StringBuilder sb = new StringBuilder();
84+
85+
List<OpCandidate> candidates = res.getCandidates();
86+
List<OpCandidate> matches = res.getMatches();
87+
88+
final OpRef ref = res.getOriginalQueries().get(0);
89+
if (matches.isEmpty()) {
90+
// no matches
91+
sb.append("No matching '" + ref.getLabel() + "' op\n");
92+
} else {
93+
// multiple matches
94+
final double priority = OpUtils.getPriority(matches.get(0));
95+
sb.append("Multiple '" + ref.getLabel() + "' ops of priority " + priority + ":\n");
96+
if (OpUtils.typeCheckingIncomplete(matches)) {
97+
sb.append("Incomplete output type checking may have occured!\n");
98+
}
99+
int count = 0;
100+
for (final OpCandidate match : matches) {
101+
sb.append(++count + ". ");
102+
sb.append(match.toString() + "\n");
103+
}
104+
}
105+
106+
// fail, with information about the request and candidates
107+
sb.append("\n");
108+
sb.append("Request:\n");
109+
sb.append("-\t" + ref.toString() + "\n");
110+
sb.append("\n");
111+
sb.append("Candidates:\n");
112+
if (candidates.isEmpty()) {
113+
sb.append("-\t No candidates found!");
114+
}
115+
int count = 0;
116+
for (final OpCandidate candidate : candidates) {
117+
sb.append(++count + ". ");
118+
sb.append("\t" + OpUtils.opString(candidate.opInfo(), candidate.getStatusItem()) + "\n");
119+
final String status = candidate.getStatus();
120+
if (status != null)
121+
sb.append("\t" + status + "\n");
122+
if (candidate.getStatusCode() == StatusCode.DOES_NOT_CONFORM) {
123+
// TODO: Conformity not yet implemented
124+
// // show argument values when a contingent op rejects them
125+
// for (final ModuleItem<?> item : inputs(info)) {
126+
// final Object value = item.getValue(candidate.getModule());
127+
// sb.append("\t\t" + item.getName() + " = " + value + "\n");
128+
// }
129+
}
130+
}
131+
return sb.toString();
132+
}
66133
}

scijava/scijava-ops/src/main/java/org/scijava/ops/matcher/OpMatcher.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333

3434
import org.scijava.ops.Hints;
35+
import org.scijava.ops.OpCandidate;
3536
import org.scijava.ops.OpEnvironment;
3637
import org.scijava.ops.OpRef;
3738

0 commit comments

Comments
 (0)