4545import org .scijava .struct .MemberInstance ;
4646import org .scijava .struct .Struct ;
4747import org .scijava .struct .StructInstance ;
48+ import org .scijava .struct .ValueAccessible ;
4849
4950/**
5051 * Utility methods for working with ops.
@@ -159,36 +160,53 @@ public static double getPriority(final OpCandidate candidate) {
159160 return candidate .opInfo ().priority ();
160161 }
161162
162- public static Type [] padArgs (final OpCandidate candidate ) {
163+ public static Type [] padTypes (final OpCandidate candidate , Type [] types ) {
164+ return (Type []) padArgs (candidate , false , (Object [])types );
165+ }
166+
167+ public static Object [] padArgs (final OpCandidate candidate , final boolean secondary , Object ... args ) {
168+ List <Member <?>> members ;
169+ String argName ;
170+ if (secondary ) {
171+ members = OpUtils .injectableMembers (candidate .struct ());
172+ argName = "secondary args" ;
173+ } else {
174+ members = OpUtils .inputs (candidate .struct ());
175+ argName = "args" ;
176+ }
177+
163178 int inputCount = 0 , requiredCount = 0 ;
164- for (final Member <?> item : OpUtils . inputs ( candidate . struct ()) ) {
179+ for (final Member <?> item : members ) {
165180 inputCount ++;
166181 if (isRequired (item ))
167182 requiredCount ++;
168183 }
169- final Type [] args = candidate .getRef ().getArgs ();
170184 if (args .length == inputCount ) {
171185 // correct number of arguments
172186 return args ;
173187 }
174188 if (args .length > inputCount ) {
175189 // too many arguments
176- candidate .setStatus (StatusCode .TOO_MANY_ARGS , args .length + " > " + inputCount );
190+ candidate .setStatus (StatusCode .TOO_MANY_ARGS ,
191+ "\n Number of " + argName + " given: " + args .length + " > " +
192+ "Number of " + argName + " of op: " + inputCount );
177193 return null ;
178194 }
179195 if (args .length < requiredCount ) {
180196 // too few arguments
181- candidate .setStatus (StatusCode .TOO_FEW_ARGS , args .length + " < " + requiredCount );
197+ candidate .setStatus (StatusCode .TOO_FEW_ARGS ,
198+ "\n Number of " + argName + " given: " + args .length + " <" +
199+ "Number of required " + argName + " of op: " + requiredCount );
182200 return null ;
183201 }
184202
185203 // pad optional parameters with null (from right to left)
186204 final int argsToPad = inputCount - args .length ;
187205 final int optionalCount = inputCount - requiredCount ;
188206 final int optionalsToFill = optionalCount - argsToPad ;
189- final Type [] paddedArgs = new Type [inputCount ];
207+ final Object [] paddedArgs = new Object [inputCount ];
190208 int argIndex = 0 , paddedIndex = 0 , optionalIndex = 0 ;
191- for (final Member <?> item : candidate . struct (). members () ) {
209+ for (final Member <?> item : members ) {
192210 if (!isRequired (item ) && optionalIndex ++ >= optionalsToFill ) {
193211 // skip this optional parameter (pad with null)
194212 paddedIndex ++;
@@ -203,6 +221,13 @@ public static boolean isRequired(final Member<?> item) {
203221 return item instanceof ParameterMember && //
204222 ((ParameterMember <?>) item ).isRequired ();
205223 }
224+
225+ public static List <Member <?>> injectableMembers (Struct struct ) {
226+ return struct .members ()
227+ .stream ()
228+ .filter (m -> m instanceof ValueAccessible )
229+ .collect (Collectors .toList ());
230+ }
206231
207232 /**
208233 * Checks if incomplete type matching could have occurred. If we have
0 commit comments