2929
3030package org .scijava .ops ;
3131
32+ import java .lang .reflect .ParameterizedType ;
3233import java .lang .reflect .Type ;
3334import java .util .Arrays ;
3435import java .util .List ;
3536import java .util .stream .Collectors ;
3637
38+ import org .scijava .ops .matcher .DefaultOpTypeMatchingService ;
3739import org .scijava .ops .matcher .MatchingResult ;
3840import org .scijava .ops .matcher .OpCandidate ;
3941import org .scijava .ops .matcher .OpInfo ;
@@ -80,15 +82,15 @@ public static List<Member<?>> inputs(final Struct struct) {
8082 }
8183
8284 public static Type [] inputTypes (OpCandidate candidate ) {
83- return inputs (candidate .struct ()). stream (). map ( m -> m . getType ()). toArray ( Type []:: new );
85+ return getTypes ( inputs (candidate .struct ()));
8486 }
8587
8688 public static List <Member <?>> outputs (OpCandidate candidate ) {
8789 return outputs (candidate .struct ());
8890 }
89-
91+
9092 public static Type [] outputTypes (OpCandidate candidate ) {
91- return outputs (candidate .struct ()). stream (). map ( m -> m . getType ()). toArray ( Type []:: new );
93+ return getTypes ( outputs (candidate .struct ()));
9294 }
9395
9496 public static List <Member <?>> outputs (final Struct struct ) {
@@ -102,13 +104,17 @@ public static List<MemberInstance<?>> outputs(StructInstance<?> op) {
102104 .filter (memberInstance -> memberInstance .member ().isOutput ()) //
103105 .collect (Collectors .toList ());
104106 }
107+
108+ public static Type [] types (OpCandidate candidate ) {
109+ return getTypes (candidate .struct ().members ());
110+ }
105111
106112 public static double getPriority (final OpCandidate candidate ) {
107113 // TODO: Think about what to do about non @Plugin-based ops...?
108114 // What if there is no annotation? How to discern a priority?
109115 return candidate .opInfo ().getAnnotation ().priority ();
110116 }
111-
117+
112118 public static Type [] padArgs (final OpCandidate candidate ) {
113119 int inputCount = 0 , requiredCount = 0 ;
114120 for (final Member <?> item : OpUtils .inputs (candidate .struct ())) {
@@ -154,6 +160,33 @@ public static boolean isRequired(final Member<?> item) {
154160 ((ParameterMember <?>) item ).isRequired ();
155161 }
156162
163+ /**
164+ * Checks if incomplete type matching could have occurred. If we have
165+ * several matches that do not have equal output types, output types may not
166+ * completely match the request as only raw type assignability will be checked
167+ * at the moment.
168+ * @see DefaultOpTypeMatchingService#typesMatch(OpCandidate)
169+ * @param matches
170+ * @return
171+ */
172+ private static boolean typeCheckingIncomplete (List <OpCandidate > matches ) {
173+ Type [] outputTypes = null ;
174+ for (OpCandidate match : matches ) {
175+ Type [] ts = getTypes (outputs (match ));
176+ if (outputTypes == null || Arrays .deepEquals (outputTypes , ts )) {
177+ outputTypes = ts ;
178+ continue ;
179+ } else {
180+ return true ;
181+ }
182+ }
183+ return false ;
184+ }
185+
186+ public static Type [] getTypes (List <Member <?>> members ) {
187+ return members .stream ().map (m -> m .getType ()).toArray (Type []::new );
188+ }
189+
157190 /**
158191 * Gets a string with an analysis of a particular match request failure.
159192 * <p>
@@ -174,14 +207,17 @@ public static String matchInfo(final MatchingResult res) {
174207 List <OpCandidate > candidates = res .getCandidates ();
175208 List <OpCandidate > matches = res .getMatches ();
176209
177- final OpRef ref = candidates . get ( 0 ). getRef ( );
210+ final OpRef ref = res . getOriginalQueries (). get ( 0 );
178211 if (matches .isEmpty ()) {
179212 // no matches
180213 sb .append ("No matching '" + ref .getLabel () + "' op\n " );
181214 } else {
182215 // multiple matches
183216 final double priority = getPriority (matches .get (0 ));
184217 sb .append ("Multiple '" + ref .getLabel () + "' ops of priority " + priority + ":\n " );
218+ if (typeCheckingIncomplete (matches )) {
219+ sb .append ("Incomplete output type checking may have occured!\n " );
220+ }
185221 int count = 0 ;
186222 for (final OpCandidate match : matches ) {
187223 sb .append (++count + ". " );
0 commit comments