2424import org .scijava .ops .FieldOpDependencyMember ;
2525import org .scijava .ops .OpDependency ;
2626import org .scijava .ops .OpDependencyMember ;
27+ import org .scijava .ops .matcher .OpInfo ;
2728import org .scijava .struct .ItemIO ;
2829import org .scijava .struct .Member ;
2930import org .scijava .struct .Struct ;
@@ -80,6 +81,12 @@ public static Struct structOf(final Field field)
8081 final List <Member <?>> items = parse (field );
8182 return () -> items ;
8283 }
84+
85+ //TODO: Javadoc
86+ public static Struct structOf (final OpInfo opInfo , final Type newType ) throws ValidityException {
87+ final List <Member <?>> items = parse (opInfo , newType );
88+ return () -> items ;
89+ }
8390
8491 /**
8592 * Parses the specified functional class for @{@link Parameter} annotations. This consists of the following steps:
@@ -113,7 +120,7 @@ public static List<Member<?>> parse(final Class<?> type)
113120 // Parse class level (i.e., generic) @Parameter annotations.
114121 final Class <?> paramsClass = findParametersDeclaration (type );
115122 if (paramsClass != null ) {
116- parseFunctionalParameters (items , names , problems , paramsClass , type );
123+ parseFunctionalParameters (items , names , problems , paramsClass , type , false );
117124 }
118125
119126 // Parse field level @OpDependency annotations.
@@ -145,7 +152,23 @@ public static List<Member<?>> parse(final Field field) throws ValidityException
145152 final Type fieldType = Types .fieldType (field , c );
146153
147154 checkModifiers (field .toString () + ": " , problems , field .getModifiers (), false , Modifier .FINAL );
148- parseFunctionalParameters (items , names , problems , field , fieldType );
155+ parseFunctionalParameters (items , names , problems , field , fieldType , false );
156+
157+ // Fail if there were any problems.
158+ if (!problems .isEmpty ()) {
159+ throw new ValidityException (problems );
160+ }
161+
162+ return items ;
163+ }
164+
165+ //TODO: Javadoc
166+ public static List <Member <?>> parse (final OpInfo opInfo , final Type newType ) throws ValidityException {
167+ final ArrayList <Member <?>> items = new ArrayList <>();
168+ final ArrayList <ValidityProblem > problems = new ArrayList <>();
169+ final Set <String > names = new HashSet <>();
170+
171+ parseFunctionalParameters (items , names , problems , opInfo .getAnnotationBearer (), newType , true );
149172
150173 // Fail if there were any problems.
151174 if (!problems .isEmpty ()) {
@@ -311,7 +334,7 @@ private static boolean resolveItemIOAuto(Parameter[] annotations, List<Functiona
311334 }
312335
313336 private static void parseFunctionalParameters (final ArrayList <Member <?>> items , final Set <String > names , final ArrayList <ValidityProblem > problems ,
314- AnnotatedElement annotationBearer , Type type ) {
337+ AnnotatedElement annotationBearer , Type type , final boolean synthesizeAnnotations ) {
315338 //Search for the functional method of 'type' and map its signature to ItemIO
316339 List <FunctionalMethodType > fmts = findFunctionalMethodTypes (type );
317340 if (fmts == null ) {
@@ -322,7 +345,7 @@ private static void parseFunctionalParameters(final ArrayList<Member<?>> items,
322345 // Get parameter annotations (may not be present)
323346 Parameter [] annotations = AnnotationUtils .parameters (annotationBearer );
324347 // 'type' is annotated, resolve ItemIO.AUTO by matching it to the signature of the functional method
325- if (annotations .length > 0 ) {
348+ if (annotations .length > 0 && ! synthesizeAnnotations ) {
326349 if (annotations .length != fmts .size ()) {
327350 String fmtIOs = Arrays .deepToString (fmts .stream ().map (fmt -> fmt .itemIO ()).toArray (ItemIO []::new ));
328351 problems .add (new ValidityProblem ("The number of inferred functional method types does not match "
0 commit comments