3535public class CompletionCandidate implements Comparable <CompletionCandidate > {
3636 private final String elementName ;
3737 private final String label ; // the toString value
38- private final String completionString ;
38+ private final String completion ;
3939 private final Object wrappedObject ;
4040 private final int type ;
4141
@@ -48,60 +48,61 @@ public class CompletionCandidate implements Comparable<CompletionCandidate> {
4848 static final int LOCAL_VAR = 6 ;
4949
5050
51- public CompletionCandidate (Method method ) {
51+ CompletionCandidate (Method method ) {
52+ // return value ignored? [fry 180326]
5253 method .getDeclaringClass ().getName ();
5354 elementName = method .getName ();
54- StringBuilder label = new StringBuilder ("<html>" +method .getName () + "(" );
55- StringBuilder cstr = new StringBuilder (method .getName () + "(" );
56- for (int i = 0 ; i < method .getParameterTypes ().length ; i ++) {
57- label .append (method .getParameterTypes ()[i ].getSimpleName ());
58- if (i < method .getParameterTypes ().length - 1 ) {
59- label .append ("," );
60- cstr .append ("," );
55+
56+ StringBuilder labelBuilder = new StringBuilder ("<html>" +method .getName () + "(" );
57+ StringBuilder compBuilder = new StringBuilder (method .getName () + "(" );
58+ Class <?>[] types = method .getParameterTypes ();
59+ for (int i = 0 ; i < types .length ; i ++) {
60+ labelBuilder .append (types [i ].getSimpleName ());
61+ if (i < types .length - 1 ) {
62+ labelBuilder .append (',' );
63+ compBuilder .append (',' );
6164 }
6265 }
63- if ( method . getParameterTypes () .length == 1 ) {
64- cstr .append (' ' );
66+ if ( types .length == 1 ) {
67+ compBuilder .append (' ' );
6568 }
66- label .append (")" );
67- if (method .getReturnType () != null )
68- label .append (" : " + method .getReturnType ().getSimpleName ());
69- label .append (" - <font color=#777777>" + method .getDeclaringClass ().getSimpleName () + "</font></html>" );
70- cstr .append (")" );
71- this .label = label .toString ();
72- this .completionString = cstr .toString ();
69+ labelBuilder .append (")" );
70+
71+ if (method .getReturnType () != null ) {
72+ labelBuilder .append (" : " + method .getReturnType ().getSimpleName ());
73+ }
74+ labelBuilder .append (" - <font color=#777777>" + method .getDeclaringClass ().getSimpleName () + "</font></html>" );
75+
76+ compBuilder .append (")" );
77+ label = labelBuilder .toString ();
78+ completion = compBuilder .toString ();
79+
7380 type = PREDEF_METHOD ;
7481 wrappedObject = method ;
7582 }
7683
77- public Object getWrappedObject () {
78- return wrappedObject ;
79- }
8084
81- public CompletionCandidate (SingleVariableDeclaration svd ) {
82- completionString = svd .getName ().toString ();
85+ CompletionCandidate (SingleVariableDeclaration svd ) {
86+ completion = svd .getName ().toString ();
8387 elementName = svd .getName ().toString ();
84- if (svd .getParent () instanceof FieldDeclaration )
85- type = LOCAL_FIELD ;
86- else
87- type = LOCAL_VAR ;
88+ type = (svd .getParent () instanceof FieldDeclaration ) ?
89+ LOCAL_FIELD : LOCAL_VAR ;
8890 label = svd .getName () + " : " + svd .getType ();
8991 wrappedObject = svd ;
9092 }
9193
92- public CompletionCandidate (VariableDeclarationFragment vdf ) {
93- completionString = vdf .getName ().toString ();
94+
95+ CompletionCandidate (VariableDeclarationFragment vdf ) {
96+ completion = vdf .getName ().toString ();
9497 elementName = vdf .getName ().toString ();
95- if (vdf .getParent () instanceof FieldDeclaration )
96- type = LOCAL_FIELD ;
97- else
98- type = LOCAL_VAR ;
98+ type = (vdf .getParent () instanceof FieldDeclaration ) ?
99+ LOCAL_FIELD : LOCAL_VAR ;
99100 label = vdf .getName () + " : " + CompletionGenerator .extracTypeInfo2 (vdf );
100101 wrappedObject = vdf ;
101102 }
102103
103- public CompletionCandidate ( MethodDeclaration method ) {
104- // log("ComCan " + method.getName());
104+
105+ CompletionCandidate ( MethodDeclaration method ) {
105106 elementName = method .getName ().toString ();
106107 type = LOCAL_METHOD ;
107108
@@ -126,176 +127,172 @@ public CompletionCandidate(MethodDeclaration method) {
126127 label .append (" : " + method .getReturnType2 ());
127128 cstr .append (")" );
128129 this .label = label .toString ();
129- this .completionString = cstr .toString ();
130+ this .completion = cstr .toString ();
130131 wrappedObject = method ;
131132 }
132133
133- public CompletionCandidate (TypeDeclaration td ){
134+
135+ CompletionCandidate (TypeDeclaration td ) {
134136 type = LOCAL_CLASS ;
135137 elementName = td .getName ().toString ();
136138 label = elementName ;
137- completionString = elementName ;
139+ completion = elementName ;
138140 wrappedObject = td ;
139141 }
140142
141- public CompletionCandidate (Field f ) {
143+
144+ CompletionCandidate (Field f ) {
142145 f .getDeclaringClass ().getName ();
143146 elementName = f .getName ();
144147 type = PREDEF_FIELD ;
145- // "<html>"
146- // + matchedClass + " : " + "<font color=#777777>"
147- // + matchedClass2.substring(0, d) + "</font>", matchedClass
148- // + "</html>"
149148 label = "<html>" + f .getName () + " : " + f .getType ().getSimpleName () +
150149 " - <font color=#777777>" + f .getDeclaringClass ().getSimpleName () +
151150 "</font></html>" ;
152- completionString = elementName ;
151+ completion = elementName ;
153152 wrappedObject = f ;
154153 }
155154
156- public CompletionCandidate (String name , String labelStr , String completionStr , int type ) {
157- elementName = name ;
158- label = labelStr ;
159- completionString = completionStr ;
160- this .type = type ;
161- wrappedObject = null ;
155+
156+ public CompletionCandidate (String name , String label , String completion , int type ) {
157+ this (name , label , completion , type , null );
162158 }
163159
160+
164161 public CompletionCandidate (String name , int type ) {
165- elementName = name ;
166- label = name ;
167- completionString = name ;
168- this .type = type ;
169- wrappedObject = null ;
162+ this (name , name , name , type , null );
170163 }
171164
165+
172166 private CompletionCandidate (String elementName , String label ,
173- String completionString , int type ,
167+ String completion , int type ,
174168 Object wrappedObject ) {
175169 this .elementName = elementName ;
176170 this .label = label ;
177- this .completionString = completionString ;
171+ this .completion = completion ;
178172 this .type = type ;
179173 this .wrappedObject = wrappedObject ;
180174 }
181175
176+
177+ Object getWrappedObject () {
178+ return wrappedObject ;
179+ }
180+
181+
182182 public String getElementName () {
183183 return elementName ;
184184 }
185185
186+
186187 public String getCompletionString () {
187- return completionString ;
188+ return completion ;
188189 }
189190
191+
190192 public String toString () {
191193 return label ;
192194 }
193195
196+
194197 public int getType () {
195198 return type ;
196199 }
197200
201+
198202 public String getLabel () {
199203 return label ;
200204 }
201205
206+
202207 public String getNoHtmlLabel (){
203- if (!label .contains ("<html>" )) {
208+ if (!label .contains ("<html>" )) {
204209 return label ;
205- }
206- else {
210+
211+ } else {
212+ // TODO this is gross [fry 180326]
207213 StringBuilder ans = new StringBuilder (label );
208- while (ans .indexOf ("<" ) > -1 ) {
214+ while (ans .indexOf ("<" ) > -1 ) {
209215 int a = ans .indexOf ("<" ), b = ans .indexOf (">" );
210- if (a > b ) break ;
216+ if (a > b ) break ;
211217 ans .replace (a , b +1 , "" );
212- // System.out.println(ans.replace(a, b+1, ""));
213- // System.out.println(ans + "--");
214218 }
215219 return ans .toString ();
216220 }
217221 }
218222
223+
219224 public CompletionCandidate withLabelAndCompString (String label ,
220- String completionString ) {
221- return new CompletionCandidate (this .elementName , label , completionString ,
225+ String completion ) {
226+ return new CompletionCandidate (this .elementName , label , completion ,
222227 this .type , this .wrappedObject );
223228 }
224229
230+
225231 @ Override
226232 public int compareTo (CompletionCandidate cc ) {
227- if (type != cc .getType ()){
233+ if (type != cc .getType ()) {
228234 return cc .getType () - type ;
229235 }
230- return ( elementName .compareTo (cc .getElementName () ));
236+ return elementName .compareTo (cc .getElementName ());
231237 }
232238
239+
233240 public CompletionCandidate withRegeneratedCompString () {
234241 if (wrappedObject instanceof MethodDeclaration ) {
235242 MethodDeclaration method = (MethodDeclaration )wrappedObject ;
236243
237244 @ SuppressWarnings ("unchecked" )
238245 List <ASTNode > params = (List <ASTNode >)
239- method .getStructuralProperty (MethodDeclaration .PARAMETERS_PROPERTY );
246+ method .getStructuralProperty (MethodDeclaration .PARAMETERS_PROPERTY );
240247
241- StringBuilder label = new StringBuilder (elementName + "(" );
242- StringBuilder cstr = new StringBuilder (method .getName () + "(" );
248+ StringBuilder labelBuilder = new StringBuilder (elementName + "(" );
249+ StringBuilder compBuilder = new StringBuilder (method .getName () + "(" );
243250 for (int i = 0 ; i < params .size (); i ++) {
244- label .append (params .get (i ). toString ( ));
251+ labelBuilder .append (params .get (i ));
245252 if (i < params .size () - 1 ) {
246- label .append ("," );
247- cstr .append ("," );
253+ labelBuilder .append (',' );
254+ compBuilder .append (',' );
248255 }
249256 }
250257 if (params .size () == 1 ) {
251- cstr .append (' ' );
258+ compBuilder .append (' ' );
252259 }
253- label .append (")" );
254- if (method .getReturnType2 () != null )
255- label .append (" : " + method .getReturnType2 ());
256- cstr .append (")" );
257- return this .withLabelAndCompString (label .toString (), cstr .toString ());
258- }
259- else if (wrappedObject instanceof Method ) {
260- Method method = (Method )wrappedObject ;
261- StringBuilder label = new StringBuilder ("<html>" + method .getName () + "(" );
262- StringBuilder cstr = new StringBuilder (method .getName () + "(" );
263- for (int i = 0 ; i < method .getParameterTypes ().length ; i ++) {
264- label .append (method .getParameterTypes ()[i ].getSimpleName ());
265- if (i < method .getParameterTypes ().length - 1 ) {
266- label .append ("," );
267- cstr .append ("," );
268- }
269- }
270- if (method .getParameterTypes ().length == 1 ) {
271- cstr .append (' ' );
272- }
273- label .append (")" );
274- if (method .getReturnType () != null )
275- label .append (" : " + method .getReturnType ().getSimpleName ());
276- label .append (" - <font color=#777777>" + method .getDeclaringClass ().getSimpleName () + "</font></html>" );
277- cstr .append (")" );
278- return this .withLabelAndCompString (label .toString (), cstr .toString ());
279- /*
280- * StringBuilder label = new StringBuilder("<html>"+method.getName() + "(");
281- StringBuilder cstr = new StringBuilder(method.getName() + "(");
282- for (int i = 0; i < method.getParameterTypes().length; i++) {
283- label.append(method.getParameterTypes()[i].getSimpleName());
284- if (i < method.getParameterTypes().length - 1) {
285- label.append(",");
286- cstr.append(",");
260+ labelBuilder .append (')' );
261+ if (method .getReturnType2 () != null ) {
262+ labelBuilder .append (" : " );
263+ labelBuilder .append (method .getReturnType2 ());
287264 }
265+ compBuilder .append (')' );
266+ return withLabelAndCompString (labelBuilder .toString (), compBuilder .toString ());
267+
268+ } else if (wrappedObject instanceof Method ) {
269+ Method method = (Method ) wrappedObject ;
270+ StringBuilder labelBuilder = new StringBuilder ("<html>" + method .getName () + "(" );
271+ StringBuilder compBuilder = new StringBuilder (method .getName () + "(" );
272+ for (int i = 0 ; i < method .getParameterTypes ().length ; i ++) {
273+ labelBuilder .append (method .getParameterTypes ()[i ].getSimpleName ());
274+ if (i < method .getParameterTypes ().length - 1 ) {
275+ labelBuilder .append (',' );
276+ compBuilder .append (',' );
277+ }
278+ }
279+ if (method .getParameterTypes ().length == 1 ) {
280+ compBuilder .append (' ' );
281+ }
282+ compBuilder .append (')' );
283+
284+ labelBuilder .append (')' );
285+ if (method .getReturnType () != null ) {
286+ labelBuilder .append (" : " + method .getReturnType ().getSimpleName ());
287+ }
288+ labelBuilder .append (" - <font color=#777777>" );
289+ labelBuilder .append (method .getDeclaringClass ().getSimpleName ());
290+ labelBuilder .append ("</font></html>" );
291+
292+ return withLabelAndCompString (labelBuilder .toString (), compBuilder .toString ());
288293 }
289- if(method.getParameterTypes().length == 1) {
290- cstr.append(' ');
291- }
292- label.append(")");
293- if(method.getReturnType() != null)
294- label.append(" : " + method.getReturnType().getSimpleName());
295- label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
296- * */
297- }
294+
295+ // fall-through silently does nothing? [fry 180326]
298296 return this ;
299297 }
300-
301298}
0 commit comments