2929
3030package org .scijava .ops ;
3131
32- import java .lang .reflect .ParameterizedType ;
3332import java .lang .reflect .Type ;
3433import java .util .Arrays ;
3534import java .util .List ;
3837import org .scijava .ops .matcher .DefaultOpTypeMatchingService ;
3938import org .scijava .ops .matcher .MatchingResult ;
4039import org .scijava .ops .matcher .OpCandidate ;
40+ import org .scijava .ops .matcher .OpCandidate .StatusCode ;
4141import org .scijava .ops .matcher .OpInfo ;
4242import org .scijava .ops .matcher .OpRef ;
43- import org .scijava .ops .matcher .OpCandidate .StatusCode ;
4443import org .scijava .param .ParameterMember ;
4544import org .scijava .struct .Member ;
4645import org .scijava .struct .MemberInstance ;
@@ -61,8 +60,55 @@ private OpUtils() {
6160
6261 // -- Utility methods --
6362
63+ /**
64+ * The canonical op name is defined as the first name in the list of op
65+ * names used for each op. This method will call
66+ * {@link #parseOpNames(String)} and return the first one.
67+ *
68+ * @param names
69+ * @return
70+ */
71+ public static String getCanonicalOpName (String names ) {
72+ return parseOpNames (names )[0 ];
73+ }
74+
75+ /**
76+ * Parses op names contained in specified String according to the following
77+ * format:
78+ *
79+ * <pre>
80+ * 'prefix1'.'prefix2' , 'prefix1'.'prefix3'
81+ * </pre>
82+ *
83+ * E.g. "math.add, math.pow". </br>
84+ * The name delimiter is a comma (,). Furthermore, names without prefixes
85+ * are added. The above example will result in the following output:
86+ *
87+ * <pre>
88+ * [math.add, add, math.pow, pow]
89+ * </pre>
90+ *
91+ * @param names
92+ * the string containing the names to parse
93+ * @return
94+ */
6495 public static String [] parseOpNames (String names ) {
65- return Arrays .stream (names .split ("," )).map (s -> s .trim ()).toArray (String []::new );
96+ return Arrays .stream (names .split ("," )).map (s -> s .trim ()).flatMap (s -> Arrays .stream (parseOpName (s )))
97+ .toArray (String []::new );
98+ }
99+
100+ /**
101+ * Returns an array containing the specified name and the name without
102+ * prefixes. Prefixes are assumed to be separated by a comma (,). E.g.
103+ * "math.add" will result in [math.add, add].
104+ *
105+ * @param name
106+ * the string containing the name to parse
107+ * @return
108+ */
109+ public static String [] parseOpName (String name ) {
110+ String [] split = name .split ("\\ ." );
111+ return new String [] { name , split [split .length - 1 ] };
66112 }
67113
68114 public static List <MemberInstance <?>> inputs (StructInstance <?> op ) {
0 commit comments