Skip to content

Commit 84a5d3e

Browse files
committed
CustomFunctionCompletion.compareTo: equally named functions are listed first
when they have no arguments. Also fixes #10 which was due to issues relating to AsbtractCompletion doing String comparisons ignoring case.
1 parent 28d3ca4 commit 84a5d3e

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

‎src/main/java/org/scijava/plugins/scripteditor/jython/CustomFunctionCompletion.java‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@
2828
*/
2929
package org.scijava.plugins.scripteditor.jython;
3030

31+
import org.fife.ui.autocomplete.Completion;
3132
import org.fife.ui.autocomplete.CompletionProvider;
3233
import org.fife.ui.autocomplete.FunctionCompletion;
34+
import org.fife.ui.autocomplete.VariableCompletion;
3335

3436
public class CustomFunctionCompletion extends FunctionCompletion
3537
{
@@ -45,6 +47,10 @@ public String getName() {
4547
return super.getName() + "()"; // for listing with fields and methods
4648
}
4749

50+
protected String getSuperName() {
51+
return super.getName();
52+
}
53+
4854
@Override
4955
public String getDefinitionString() {
5056
StringBuilder sb = new StringBuilder();
@@ -96,4 +102,25 @@ public String getSummary() {
96102
return super.getShortDescription();
97103
}
98104

105+
@Override
106+
public int compareTo(final Completion c2)
107+
{
108+
if ( c2 == this ) return 0;
109+
if ( c2 instanceof CustomFunctionCompletion ) {
110+
final CustomFunctionCompletion other = (CustomFunctionCompletion)c2;
111+
int r = this.getSuperName().compareToIgnoreCase(other.getSuperName()); // must be lower case because AbstractCompletion does it that way
112+
if ( 0 == r ) {
113+
if ( this.getParamCount() == other.getParamCount() ) {
114+
for (int i=0; i<this.getParamCount(); ++i) {
115+
r = this.getParam(i).getType().compareTo(other.getParam(i).getType());
116+
if ( 0 != r ) return r;
117+
}
118+
return 0;
119+
}
120+
return this.getParamCount() < other.getParamCount() ? -1 : 1;
121+
}
122+
return r;
123+
}
124+
return this.getSuperName().compareToIgnoreCase(c2.getReplacementText()); // must be lower case because AbstractCompletion does it that way
125+
}
99126
}

0 commit comments

Comments
 (0)