2828 */
2929package org .scijava .plugins .scripteditor .jython ;
3030
31+ import org .fife .ui .autocomplete .Completion ;
3132import org .fife .ui .autocomplete .CompletionProvider ;
3233import org .fife .ui .autocomplete .FunctionCompletion ;
34+ import org .fife .ui .autocomplete .VariableCompletion ;
3335
3436public 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