3333
3434
3535public class CompletionCandidate implements Comparable <CompletionCandidate >{
36- private String elementName ;
37- private String label ; // the toString value
38- private String completionString ;
39- private Object wrappedObject ;
40- private int type ;
36+ private final String elementName ;
37+ private final String label ; // the toString value
38+ private final String completionString ;
39+ private final Object wrappedObject ;
40+ private final int type ;
4141
4242 static final int PREDEF_CLASS = 0 ;
4343 static final int PREDEF_FIELD = 1 ;
@@ -158,13 +158,25 @@ public CompletionCandidate(String name, String labelStr, String completionStr, i
158158 label = labelStr ;
159159 completionString = completionStr ;
160160 this .type = type ;
161+ wrappedObject = null ;
161162 }
162163
163164 public CompletionCandidate (String name , int type ) {
164165 elementName = name ;
165166 label = name ;
166167 completionString = name ;
167168 this .type = type ;
169+ wrappedObject = null ;
170+ }
171+
172+ private CompletionCandidate (String elementName , String label ,
173+ String completionString , int type ,
174+ Object wrappedObject ) {
175+ this .elementName = elementName ;
176+ this .label = label ;
177+ this .completionString = completionString ;
178+ this .type = type ;
179+ this .wrappedObject = wrappedObject ;
168180 }
169181
170182 public String getElementName () {
@@ -204,22 +216,21 @@ public String getNoHtmlLabel(){
204216 }
205217 }
206218
207- public void setLabel (String label ) {
208- this .label = label ;
209- }
210-
211- public void setCompletionString (String completionString ) {
212- this .completionString = completionString ;
219+ public CompletionCandidate withLabelAndCompString (String label ,
220+ String completionString ) {
221+ return new CompletionCandidate (this .elementName , label , completionString ,
222+ this .type , this .wrappedObject );
213223 }
214224
225+ @ Override
215226 public int compareTo (CompletionCandidate cc ) {
216227 if (type != cc .getType ()){
217228 return cc .getType () - type ;
218229 }
219230 return (elementName .compareTo (cc .getElementName ()));
220231 }
221232
222- public void regenerateCompletionString () {
233+ public CompletionCandidate withRegeneratedCompString () {
223234 if (wrappedObject instanceof MethodDeclaration ) {
224235 MethodDeclaration method = (MethodDeclaration )wrappedObject ;
225236
@@ -243,8 +254,7 @@ public void regenerateCompletionString(){
243254 if (method .getReturnType2 () != null )
244255 label .append (" : " + method .getReturnType2 ());
245256 cstr .append (")" );
246- this .label = label .toString ();
247- this .completionString = cstr .toString ();
257+ return this .withLabelAndCompString (label .toString (), cstr .toString ());
248258 }
249259 else if (wrappedObject instanceof Method ) {
250260 Method method = (Method )wrappedObject ;
@@ -265,8 +275,7 @@ else if (wrappedObject instanceof Method) {
265275 label .append (" : " + method .getReturnType ().getSimpleName ());
266276 label .append (" - <font color=#777777>" + method .getDeclaringClass ().getSimpleName () + "</font></html>" );
267277 cstr .append (")" );
268- this .label = label .toString ();
269- this .completionString = cstr .toString ();
278+ return this .withLabelAndCompString (label .toString (), cstr .toString ());
270279 /*
271280 * StringBuilder label = new StringBuilder("<html>"+method.getName() + "(");
272281 StringBuilder cstr = new StringBuilder(method.getName() + "(");
@@ -286,6 +295,7 @@ else if (wrappedObject instanceof Method) {
286295 label.append(" - <font color=#777777>" + method.getDeclaringClass().getSimpleName() + "</font></html>");
287296 * */
288297 }
298+ return this ;
289299 }
290300
291301}
0 commit comments