@@ -188,48 +188,35 @@ public LogService logger() {
188188 * matching the functional type and the name could not be found, if
189189 * an exception occurs during injection
190190 */
191- private void resolveOpDependencies (Object op , OpCandidate parentOp ) throws OpMatchingException {
192- // HACK: Only works with Op instances and OpRunner, not extensible.
193- // Consider extensible ways to achieve something similar e.g. extending OpInfo
194- // to support OpDependencies.
195- if (op instanceof OpRunner ) {
196- op = ((OpRunner <?>) op ).getAdaptedOp ();
197- }
198- final List <OpDependencyMember <?>> dependencies = parentOp .opInfo ()
199- .dependencies ();
191+ private List <Object > resolveOpDependencies (OpCandidate op )
192+ throws OpMatchingException
193+ {
194+ final List <OpDependencyMember <?>> dependencies = op .opInfo ().dependencies ();
195+ final List <Object > resolvedDependencies = new ArrayList <>(dependencies
196+ .size ());
200197 for (final OpDependencyMember <?> dependency : dependencies ) {
201198 final String dependencyName = dependency .getDependencyName ();
202199 final Type mappedDependencyType = Types .mapVarToTypes (new Type [] {
203- dependency .getType () }, parentOp .typeVarAssigns ())[0 ];
200+ dependency .getType () }, op .typeVarAssigns ())[0 ];
204201 final OpRef inferredRef = inferOpRef (mappedDependencyType , dependencyName ,
205- parentOp .typeVarAssigns ());
202+ op .typeVarAssigns ());
206203 if (inferredRef == null ) {
207204 throw new OpMatchingException ("Could not infer functional " +
208205 "method inputs and outputs of Op dependency field: " + dependency
209206 .getKey ());
210207 }
211- Object matchedOp = null ;
212208 try {
213- matchedOp = findOpInstance (dependencyName , inferredRef );
209+ resolvedDependencies . add ( findOpInstance (dependencyName , inferredRef ) );
214210 }
215211 catch (final Exception e ) {
216212 throw new OpMatchingException (
217- "Could not find Op that matches requested Op dependency field :" +
218- "\n Op class: " + op .getClass ().getName () + //
219- "\n Dependency field : " + dependency .getKey () + //
213+ "Could not find Op that matches requested Op dependency:" +
214+ "\n Op class: " + op .opInfo ().implementationName () + //
215+ "\n Dependency identifier : " + dependency .getKey () + //
220216 "\n \n Attempted request:\n " + inferredRef , e );
221217 }
222- try {
223- dependency .createInstance (op ).set (matchedOp );
224- }
225- catch (final Exception e ) {
226- throw new OpMatchingException (
227- "Exception trying to inject Op dependency field.\n " +
228- "\t Op dependency field to resolve: " + dependency .getKey () + "\n " +
229- "\t Found Op to inject: " + matchedOp .getClass ().getName () + "\n " +
230- "\t With inferred OpRef: " + inferredRef , e );
231- }
232218 }
219+ return resolvedDependencies ;
233220 }
234221
235222 @ SuppressWarnings ("unchecked" )
@@ -247,7 +234,8 @@ public Object findOpInstance(final String opName, final OpRef ref, final Object.
247234 try {
248235 // Find single match which matches the specified types
249236 match = matcher .findSingleMatch (this , ref );
250- op = match .createOp (secondaryArgs );
237+ final List <Object > dependencies = resolveOpDependencies (match );
238+ op = match .createOp (dependencies , secondaryArgs );
251239 } catch (OpMatchingException e ) {
252240 log .debug ("No matching Op for request: " + ref + "\n " );
253241 log .debug ("Attempting Op transformation..." );
@@ -263,17 +251,19 @@ public Object findOpInstance(final String opName, final OpRef ref, final Object.
263251 // If we found one, try to do transformation and return transformed op
264252 log .debug ("Matching Op transformation found:\n " + transformation + "\n " );
265253 try {
266- op = transformation .exceute (this , secondaryArgs );
254+ final List <Object > dependencies = resolveOpDependencies (transformation
255+ .getSourceOp ());
256+ op = transformation .exceute (this , dependencies , secondaryArgs );
267257 } catch (OpMatchingException | OpTransformationException e1 ) {
268258 throw new IllegalArgumentException ("Execution of Op transformatioon failed:\n " + e1 );
269259 }
270260 }
271261 try {
272262 // Try to resolve annotated OpDependency fields
273263 if (match != null )
274- resolveOpDependencies (op , match );
264+ resolveOpDependencies (match );
275265 else if (transformation != null )
276- resolveOpDependencies (op , transformation .getSourceOp ());
266+ resolveOpDependencies (transformation .getSourceOp ());
277267 } catch (OpMatchingException e ) {
278268 throw new IllegalArgumentException (e );
279269 }
0 commit comments