Skip to content

Commit d8115f7

Browse files
committed
New class CustomFunctionCompletion to support method completions with arguments.
1 parent 94c1ef3 commit d8115f7

1 file changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package org.scijava.plugins.scripteditor.jython;
2+
3+
import org.fife.ui.autocomplete.CompletionProvider;
4+
import org.fife.ui.autocomplete.FunctionCompletion;
5+
6+
public class CustomFunctionCompletion extends FunctionCompletion
7+
{
8+
public CustomFunctionCompletion(
9+
final CompletionProvider provider,
10+
final String name,
11+
final String returnType) {
12+
super(provider, name, returnType);
13+
}
14+
15+
@Override
16+
public String getName() {
17+
return super.getName() + "()"; // for listing with fields and methods
18+
}
19+
20+
@Override
21+
public String getDefinitionString() {
22+
StringBuilder sb = new StringBuilder();
23+
24+
// Add the return type if applicable (C macros like NULL have no type).
25+
String type = getType();
26+
if (type!=null) {
27+
sb.append(type).append(' ');
28+
}
29+
30+
// Add the item being described's name.
31+
sb.append(super.getName()); // without parentheses: will be added below with arguments inside
32+
33+
// Add parameters for functions.
34+
CompletionProvider provider = getProvider();
35+
char start = provider.getParameterListStart();
36+
if (start!=0) {
37+
sb.append(start);
38+
}
39+
for (int i=0; i<getParamCount(); i++) {
40+
Parameter param = getParam(i);
41+
type = param.getType();
42+
String name = param.getName();
43+
if (type!=null) {
44+
sb.append(type);
45+
if (name!=null) {
46+
sb.append(' ');
47+
}
48+
}
49+
if (name!=null) {
50+
sb.append(name);
51+
}
52+
if (i<super.getParamCount()-1) {
53+
sb.append(provider.getParameterListSeparator());
54+
}
55+
}
56+
char end = provider.getParameterListEnd();
57+
if (end!=0) {
58+
sb.append(end);
59+
}
60+
61+
return sb.toString();
62+
}
63+
64+
@Override
65+
public String getSummary() {
66+
// Return the CompletionText.getSummary() text, made by ClassUtil.getSummaryCompletion
67+
// (In principle, the latter is a shortcut to the whole mechanism in superclass FunctionCompletion, but that's fine.)
68+
return super.getShortDescription();
69+
}
70+
71+
}

0 commit comments

Comments
 (0)