|
48 | 48 | import org.scijava.ops.matcher.OpClassInfo; |
49 | 49 | import org.scijava.ops.matcher.OpFieldInfo; |
50 | 50 | import org.scijava.ops.matcher.OpInfo; |
| 51 | +import org.scijava.ops.matcher.OpMatchingException; |
51 | 52 | import org.scijava.ops.matcher.OpRef; |
52 | 53 | import org.scijava.ops.matcher.OpTypeMatchingService; |
53 | 54 | import org.scijava.ops.util.Inject; |
|
58 | 59 | import org.scijava.service.AbstractService; |
59 | 60 | import org.scijava.service.SciJavaService; |
60 | 61 | import org.scijava.service.Service; |
61 | | -import org.scijava.struct.StructInstance; |
62 | 62 | import org.scijava.ops.types.Nil; |
63 | 63 | import org.scijava.util.ClassUtils; |
64 | 64 |
|
@@ -154,58 +154,43 @@ public Iterable<OpInfo> infos(String name) { |
154 | 154 | return opCache.getAndBelow(new PrefixQuery(opName)); |
155 | 155 | } |
156 | 156 |
|
157 | | - public <T> StructInstance<T> findOpInstance(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, |
| 157 | + public <T> T findOpInstance(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, |
158 | 158 | final Nil<?>[] outTypes, final Object... secondaryArgs) { |
159 | 159 | final OpRef ref = OpRef.fromTypes(opName, toTypes(specialType), toTypes(outTypes), toTypes(inTypes)); |
160 | 160 |
|
161 | | - // Find single match which matches the specified types |
162 | | - OpCandidate match = findTypeMatch(ref); |
163 | | - |
164 | | - @SuppressWarnings("unchecked") |
165 | | - final StructInstance<T> opInst = (StructInstance<T>) match.createOpInstance(); |
166 | | - |
167 | | - // Inject the secondary args if there are any |
168 | | - if (Inject.Structs.isInjectable(opInst)) { |
169 | | - // Get padded secondary args |
170 | | - Object[] paddedArgs = OpUtils.padArgs(match, true, secondaryArgs); |
171 | | - if (paddedArgs == null) { |
172 | | - throw new IllegalStateException(match.opInfo().implementationName() + " | " + match.getStatus()); |
173 | | - } |
174 | | - Inject.Structs.inputs(opInst, paddedArgs); |
175 | | - // Secondary args are given, however there are no to inject |
176 | | - } else if (secondaryArgs.length > 0) { |
177 | | - log.warn( |
178 | | - "Specified Op has no secondary args, however secondary args are given. " |
179 | | - + "The specified args will not be injected."); |
| 161 | + try { |
| 162 | + // Find single match which matches the specified types |
| 163 | + OpCandidate match = findTypeMatch(ref); |
| 164 | + return (T) match.createOp(secondaryArgs); |
| 165 | + } catch (OpMatchingException e) { |
| 166 | + throw new RuntimeException(e); |
180 | 167 | } |
181 | | - return opInst; |
182 | 168 | } |
183 | | - |
184 | 169 | public <T> T findOp(final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?>[] outTypes, |
185 | 170 | final Object... secondaryArgs) { |
186 | | - return findOpInstance(null, specialType, inTypes, outTypes, secondaryArgs).object(); |
| 171 | + return findOpInstance(null, specialType, inTypes, outTypes, secondaryArgs); |
187 | 172 | } |
188 | 173 |
|
189 | 174 | public <T> T findOp(final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?> outType, |
190 | 175 | final Object... secondaryArgs) { |
191 | | - return findOpInstance(null, specialType, inTypes, new Nil[] { outType }, secondaryArgs).object(); |
| 176 | + return findOpInstance(null, specialType, inTypes, new Nil[] { outType }, secondaryArgs); |
192 | 177 | } |
193 | 178 |
|
194 | 179 | public <T> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, final Nil<?>[] outTypes, |
195 | 180 | final Object... secondaryArgs) { |
196 | | - return findOpInstance(opName, specialType, inTypes, outTypes, secondaryArgs).object(); |
| 181 | + return findOpInstance(opName, specialType, inTypes, outTypes, secondaryArgs); |
197 | 182 | } |
198 | 183 |
|
199 | 184 | public <T> T findOp(final String opName, final Nil<T> specialType, final Nil<?>[] inTypes, |
200 | 185 | final Nil<?> outType, final Object... secondaryArgs) { |
201 | | - return findOpInstance(opName, specialType, inTypes, new Nil[] { outType }, secondaryArgs).object(); |
| 186 | + return findOpInstance(opName, specialType, inTypes, new Nil[] { outType }, secondaryArgs); |
202 | 187 | } |
203 | 188 |
|
204 | 189 | public MatchingResult findTypeMatches(final OpRef ref) { |
205 | 190 | return matcher.findMatch(this, ref); |
206 | 191 | } |
207 | 192 |
|
208 | | - public OpCandidate findTypeMatch(final OpRef ref) { |
| 193 | + public OpCandidate findTypeMatch(final OpRef ref) throws OpMatchingException { |
209 | 194 | return findTypeMatches(ref).singleMatch(); |
210 | 195 | } |
211 | 196 |
|
|
0 commit comments