FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

more cleanup in completions code · mFrankowicz/processing@ff7dc4d · GitHub

Repository navigation

Commit ff7dc4d

Browse files
committed
more cleanup in completions code
1 parent 8dda8a4 commit ff7dc4d

2 files changed

Lines changed: 50 additions & 55 deletions

File tree

‎java/src/processing/mode/java/pdex/CompletionCandidate.java‎

Lines changed: 49 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/*
44
Part of the Processing project - http://processing.org
5-
Copyright (c) 2012-15 The Processing Foundation
5+
Copyright (c) 2012-18 The Processing Foundation
66
77
This program is free software; you can redistribute it and/or modify
88
it under the terms of the GNU General Public License version 2
@@ -32,6 +32,11 @@
3232
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
3333

3434

35+
// TODO when building the label in some variants in this file,
36+
// getReturnType2() is used instead of getReturnType().
37+
// need to check whether that's identical in how it performs,
38+
// and if so, use makeLabel() and makeCompletion() more [fry 180326]
39+
3540
public class CompletionCandidate implements Comparable<CompletionCandidate> {
3641
private final String elementName;
3742
private final String label; // the toString value
@@ -52,49 +57,8 @@ public class CompletionCandidate implements Comparable<CompletionCandidate> {
5257
// return value ignored? [fry 180326]
5358
method.getDeclaringClass().getName();
5459
elementName = method.getName();
55-
Class<?>[] types = method.getParameterTypes();
56-
57-
{ // html label
58-
StringBuilder labelBuilder = new StringBuilder();
59-
labelBuilder.append("<html>");
60-
labelBuilder.append(elementName);
61-
labelBuilder.append('(');
62-
63-
for (int i = 0; i < types.length; i++) {
64-
labelBuilder.append(types[i].getSimpleName());
65-
if (i < types.length - 1) {
66-
labelBuilder.append(',');
67-
}
68-
}
69-
labelBuilder.append(")");
70-
if (method.getReturnType() != null) {
71-
labelBuilder.append(" : ");
72-
labelBuilder.append(method.getReturnType().getSimpleName());
73-
}
74-
labelBuilder.append(" - <font color=#777777>");
75-
labelBuilder.append(method.getDeclaringClass().getSimpleName());
76-
labelBuilder.append("</font></html>");
77-
78-
label = labelBuilder.toString();
79-
}
80-
81-
{ // completion string
82-
StringBuilder compBuilder = new StringBuilder();
83-
compBuilder.append(elementName);
84-
compBuilder.append('(');
85-
86-
for (int i = 0; i < types.length; i++) {
87-
if (i < types.length - 1) {
88-
compBuilder.append(','); // wtf? [fry 180326]
89-
}
90-
}
91-
if (types.length == 1) {
92-
compBuilder.append(' ');
93-
}
94-
compBuilder.append(")");
95-
completion = compBuilder.toString();
96-
}
97-
60+
label = makeLabel(method);
61+
completion = makeCompletion(method);
9862
type = PREDEF_METHOD;
9963
wrappedObject = method;
10064
}
@@ -274,7 +238,8 @@ CompletionCandidate withRegeneratedCompString() {
274238
List<ASTNode> params = (List<ASTNode>)
275239
method.getStructuralProperty(MethodDeclaration.PARAMETERS_PROPERTY);
276240

277-
StringBuilder labelBuilder = new StringBuilder(elementName + "(");
241+
// build the html label
242+
StringBuilder labelBuilder = new StringBuilder(elementName);
278243
labelBuilder.append('(');
279244
for (int i = 0; i < params.size(); i++) {
280245
labelBuilder.append(params.get(i));
@@ -288,6 +253,7 @@ CompletionCandidate withRegeneratedCompString() {
288253
labelBuilder.append(method.getReturnType2());
289254
}
290255

256+
// build the completion str
291257
StringBuilder compBuilder = new StringBuilder();
292258
compBuilder.append(method.getName());
293259
compBuilder.append('(');
@@ -307,33 +273,40 @@ CompletionCandidate withRegeneratedCompString() {
307273
Method method = (Method) wrappedObject;
308274
Class<?>[] types = method.getParameterTypes();
309275

276+
// build html label
310277
StringBuilder labelBuilder = new StringBuilder();
311278
labelBuilder.append("<html>");
312279
labelBuilder.append(method.getName());
313280
labelBuilder.append('(');
314281

315-
StringBuilder compBuilder = new StringBuilder(method.getName() + "(");
316-
317282
for (int i = 0; i < types.length; i++) {
318283
labelBuilder.append(types[i].getSimpleName());
319284
if (i < types.length - 1) {
320285
labelBuilder.append(',');
321-
compBuilder.append(',');
322286
}
323287
}
324-
if (types.length == 1) {
325-
compBuilder.append(' ');
326-
}
327-
compBuilder.append(')');
328-
329288
labelBuilder.append(')');
330289
if (method.getReturnType() != null) {
331290
labelBuilder.append(" : " + method.getReturnType().getSimpleName());
332291
}
333292

334293
labelBuilder.append(" - <font color=#777777>");
335294
labelBuilder.append(method.getDeclaringClass().getSimpleName());
336-
labelBuilder.append("</font></html>");
295+
labelBuilder.append("</font>");
296+
labelBuilder.append("</html>");
297+
298+
// make completion string
299+
StringBuilder compBuilder = new StringBuilder(method.getName());
300+
compBuilder.append('(');
301+
for (int i = 0; i < types.length; i++) {
302+
if (i < types.length - 1) {
303+
compBuilder.append(',');
304+
}
305+
}
306+
if (types.length == 1) {
307+
compBuilder.append(' ');
308+
}
309+
compBuilder.append(')');
337310

338311
return withLabelAndCompString(labelBuilder.toString(), compBuilder.toString());
339312
}
@@ -364,12 +337,33 @@ static private String makeLabel(Method method) {
364337
}
365338
labelBuilder.append(" - <font color=#777777>");
366339
labelBuilder.append(method.getDeclaringClass().getSimpleName());
367-
labelBuilder.append("</font></html>");
340+
labelBuilder.append("</font>");
341+
labelBuilder.append("</html>");
368342

369343
return labelBuilder.toString();
370344
}
371345

372346

347+
static private String makeCompletion(Method method) {
348+
Class<?>[] types = method.getParameterTypes();
349+
350+
StringBuilder compBuilder = new StringBuilder();
351+
compBuilder.append(method.getName());
352+
compBuilder.append('(');
353+
354+
for (int i = 0; i < types.length; i++) {
355+
if (i < types.length - 1) {
356+
compBuilder.append(','); // wtf? [fry 180326]
357+
}
358+
}
359+
if (types.length == 1) {
360+
compBuilder.append(' ');
361+
}
362+
compBuilder.append(')');
363+
return compBuilder.toString();
364+
}
365+
366+
373367
@Override
374368
public int compareTo(CompletionCandidate cc) {
375369
if (type != cc.getType()) {

‎todo.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ X https://github.com/processing/processing/issues/5271
1414
o possible fix (just copies on click)
1515
o https://github.com/processing/processing/pull/5345
1616
_ in the docs: modify 'search.format=' in preferences.txt
17+
X refactoring inside the completion code
1718

1819
contrib
1920
X updates to Japanese translation

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL