Skip to content

Commit d732b06

Browse files
Treiblesschorlectrueden
authored andcommitted
Add op name without prefix as alias
1 parent dcece7a commit d732b06

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

src/main/java/org/scijava/ops/OpService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public Iterable<OpInfo> infos(String name) {
148148
if (name == null || name.isEmpty()) {
149149
return infos();
150150
}
151-
String opName = opAliases.get(name);
151+
String opName = opAliases.get(OpUtils.getCanonicalOpName(name));
152152
if (opName == null) {
153153
throw new IllegalArgumentException("No op infos with name: " + name + " available.");
154154
}

src/main/java/org/scijava/ops/OpUtils.java

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
package org.scijava.ops;
3131

32-
import java.lang.reflect.ParameterizedType;
3332
import java.lang.reflect.Type;
3433
import java.util.Arrays;
3534
import java.util.List;
@@ -38,9 +37,9 @@
3837
import org.scijava.ops.matcher.DefaultOpTypeMatchingService;
3938
import org.scijava.ops.matcher.MatchingResult;
4039
import org.scijava.ops.matcher.OpCandidate;
40+
import org.scijava.ops.matcher.OpCandidate.StatusCode;
4141
import org.scijava.ops.matcher.OpInfo;
4242
import org.scijava.ops.matcher.OpRef;
43-
import org.scijava.ops.matcher.OpCandidate.StatusCode;
4443
import org.scijava.param.ParameterMember;
4544
import org.scijava.struct.Member;
4645
import 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

Comments
 (0)