Skip to content

Commit 7a4a4be

Browse files
committed
rewrite simplifier to use the language functions and fix processing#3268
1 parent 9dc883c commit 7a4a4be

File tree

3 files changed

+92
-95
lines changed

3 files changed

+92
-95
lines changed

build/shared/lib/languages/PDE.properties

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -330,28 +330,29 @@ editor.status.debug.busy = Debugger busy...
330330
# Errors
331331
editor.status.warning = Warning
332332
editor.status.error = Error
333-
editor.status.error_on = Error on
334-
editor.status.missing.semi_colon = Missing a semi-colon
335-
editor.status.missing.open_sq_bracket = Missing opening square bracket
336-
editor.status.missing.closing_sq_bracket = Missing closing square bracket
337-
editor.status.missing.open_paren = Missing opening parentheses
338-
editor.status.missing.closing_paren = Missing closing parentheses
339-
editor.status.missing.open_curly_bracket = Missing opening curly bracket
340-
editor.status.missing.closing_curly_bracket = Missing closing curly bracket
341-
editor.status.missing.add = Consider adding a
333+
editor.status.error_on = Error on "%s"
334+
editor.status.missing.default = Missing "%c"
335+
editor.status.missing.semi_colon = Missing a semi-colon ";"
336+
editor.status.missing.open_sq_bracket = Missing opening square bracket "["
337+
editor.status.missing.closing_sq_bracket = Missing closing square bracket "]"
338+
editor.status.missing.open_paren = Missing opening parentheses "("
339+
editor.status.missing.closing_paren = Missing closing parentheses ")"
340+
editor.status.missing.open_curly_bracket = Missing opening curly bracket "{"
341+
editor.status.missing.closing_curly_bracket = Missing closing curly bracket "}"
342+
editor.status.missing.add = Consider adding "%s"
342343
editor.status.reserved_words = "color" and "int" are reserved words & cannot be used as variable names
343344
# methoddef, varname, classname, namefield, typeA, typeB will be replaced with the correct value during runtime (don't translate)
344-
editor.status.undefined_method = The function methoddef does not exist
345-
editor.status.empty_param = The function methoddef does not expect any parameters
346-
editor.status.wrong_param = The function methoddef expects parameters like this:
347-
editor.status.undef_global_var = The global variable varname does not exist
348-
editor.status.undef_class = The class classname does not exist
349-
editor.status.undef_var = The variable varname does not exist
350-
editor.status.undef_name = The name namefield cannot be recognized
351-
editor.status.type_mismatch = Type mismatch, typeA does not match with typeB
352-
editor.status.unused_variable = The value of the local variable varname is not used
353-
editor.status.uninitialized_variable = The local variable varname may not have been initialized
354-
editor.status.no_effect_assignment = The assignment to variable varname has no effect
345+
editor.status.undefined_method = The function %s does not exist
346+
editor.status.empty_param = The function "%s()" does not expect any parameters
347+
editor.status.wrong_param = The function "%s()" expects parameters like: "%s(%s)"
348+
editor.status.undef_global_var = The global variable "%s" does not exist
349+
editor.status.undef_class = The class "%s" does not exist
350+
editor.status.undef_var = The variable "%s" does not exist
351+
editor.status.undef_name = The name "%s" cannot be recognized
352+
editor.status.type_mismatch = Type mismatch, "%s" does not match with "%s"
353+
editor.status.unused_variable = The value of the local variable "%s" is not used
354+
editor.status.uninitialized_variable = The local variable "%s" may not have been initialized
355+
editor.status.no_effect_assignment = The assignment to variable "%s" has no effect
355356

356357
# Footer buttons
357358
editor.footer.errors = Errors

java/src/processing/mode/java/pdex/ErrorMessageSimplifier.java

Lines changed: 66 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222

2323
import java.lang.reflect.Field;
2424
import java.lang.reflect.Modifier;
25-
import java.util.ArrayList;
2625
import java.util.TreeMap;
2726

2827
import org.eclipse.jdt.core.compiler.IProblem;
2928
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
3029

3130
import processing.app.Language;
31+
import processing.core.PApplet;
32+
import processing.data.StringList;
3233

3334

3435
public class ErrorMessageSimplifier {
@@ -102,13 +103,13 @@ public static String getSimplifiedErrorMessage(Problem problem) {
102103

103104
case IProblem.ParsingError:
104105
if (args.length > 0) {
105-
result = Language.text("editor.status.error_on") + qs(args[0]);
106+
result = Language.interpolate("editor.status.error_on", args[0]);
106107
}
107108
break;
108109

109110
case IProblem.ParsingErrorDeleteToken:
110111
if (args.length > 0) {
111-
result = Language.text("editor.status.error_on") + qs(args[0]);
112+
result = Language.interpolate("editor.status.error_on", args[0]);
112113
}
113114
break;
114115

@@ -119,13 +120,13 @@ public static String getSimplifiedErrorMessage(Problem problem) {
119120

120121
} else {
121122
if (args[0].equals("AssignmentOperator Expression")) {
122-
result = Language.text("editor.status.missing.add") + qs("=");
123+
result = Language.interpolate("editor.status.missing.add", "=");
123124

124125
} else if (args[0].equalsIgnoreCase(") Statement")) {
125126
result = getErrorMessageForBracket(args[0].charAt(0));
126127

127128
} else {
128-
result = Language.text("editor.status.error_on") + qs(args[0]);
129+
result = Language.interpolate("editor.status.error_on", args[0]);
129130
}
130131
}
131132
}
@@ -137,10 +138,10 @@ public static String getSimplifiedErrorMessage(Problem problem) {
137138
if (args[0].equals("int")) {
138139
result = Language.text ("editor.status.reserved_words");
139140
} else {
140-
result = Language.text("editor.status.error_on") + qs(args[0]);
141+
result = Language.interpolate("editor.status.error_on", args[0]);
141142
}
142143
} else {
143-
result = Language.text("editor.status.error_on") + qs(args[0]);
144+
result = Language.interpolate("editor.status.error_on", args[0]);
144145
}
145146
}
146147
break;
@@ -151,12 +152,13 @@ public static String getSimplifiedErrorMessage(Problem problem) {
151152
result = getErrorMessageForBracket(args[1].charAt(0));
152153
}
153154
else {
154-
if(args[1].equalsIgnoreCase("Statement")){ // See #3104
155-
result = Language.text("editor.status.error_on") + qs(args[0]);
156-
}
157-
else {
158-
result = Language.text("editor.status.error_on") +
159-
" \"" + args[0] + Language.text("editor.status.missing.add") + args[1] + "\"";
155+
// https://github.com/processing/processing/issues/3104
156+
if (args[1].equalsIgnoreCase("Statement")) {
157+
result = Language.interpolate("editor.status.error_on", args[0]);
158+
} else {
159+
result =
160+
Language.interpolate("editor.status.error_on", args[0]) + " " +
161+
Language.interpolate("editor.status.missing.add", args[1]);
160162
}
161163
}
162164
}
@@ -166,7 +168,7 @@ public static String getSimplifiedErrorMessage(Problem problem) {
166168
if (args.length > 2) {
167169
result = Language.text("editor.status.undefined_method");
168170
String methodDef = "\"" + args[args.length - 2] + "("
169-
+ getSimpleName (args[args.length - 1]) + ")\"";
171+
+ removePackagePrefixes (args[args.length - 1]) + ")\"";
170172
result = result.replace("methoddef", methodDef);
171173
}
172174
break;
@@ -176,75 +178,66 @@ public static String getSimplifiedErrorMessage(Problem problem) {
176178
// 2nd arg is method name, 3rd arg is correct param list
177179
if (args[2].trim().length() == 0) {
178180
// the case where no params are needed.
179-
result = Language.text("editor.status.empty_param");
180-
String methodDef = "\"" + args[1] + "()\"";
181-
result = result.replace("methoddef", methodDef);
181+
result = Language.interpolate("editor.status.empty_param", args[1]);
182182

183183
} else {
184-
result = Language.text("editor.status.wrong_param");
185-
186-
String method = q(args[1]);
187-
String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\"";
188-
result = result.replace("method", method);
189-
result += methodDef;
184+
result = Language.interpolate("editor.status.wrong_param",
185+
args[1], args[1], removePackagePrefixes(args[2]));
186+
// String method = q(args[1]);
187+
// String methodDef = " \"" + args[1] + "(" + getSimpleName(args[2]) + ")\"";
188+
// result = result.replace("method", method);
189+
// result += methodDef;
190190
}
191191
}
192192
break;
193193

194194
case IProblem.UndefinedField:
195195
if (args.length > 0) {
196-
result = Language.text("editor.status.undef_global_var");
197-
result = result.replace("varname", q(args[0]));
196+
result = Language.interpolate("editor.status.undef_global_var", args[0]);
198197
}
199198
break;
200199

201200
case IProblem.UndefinedType:
202201
if (args.length > 0) {
203-
result = Language.text("editor.status.undef_class");
204-
result = result.replace("classname", q(args[0]));
202+
result = Language.interpolate("editor.status.undef_class", args[0]);
205203
}
206204
break;
207205

208206
case IProblem.UnresolvedVariable:
209207
if (args.length > 0) {
210-
result = Language.text("editor.status.undef_var");
211-
result = result.replace("varname", q(args[0]));
208+
result = Language.interpolate("editor.status.undef_var", args[0]);
212209
}
213210
break;
214211

215212
case IProblem.UndefinedName:
216213
if (args.length > 0) {
217-
result = Language.text("editor.status.undef_name");
218-
result = result.replace("namefield", q(args[0]));
214+
result = Language.interpolate("editor.status.undef_name", args[0]);
219215
}
220216
break;
221217

222218
case IProblem.TypeMismatch:
223219
if (args.length > 1) {
224-
result = Language.text("editor.status.type_mismatch");
225-
result = result.replace("typeA", q(args[0]));
226-
result = result.replace("typeB", q(args[1]));
220+
result = Language.interpolate("editor.status.type_mismatch", args[0], args[1]);
221+
// result = result.replace("typeA", q(args[0]));
222+
// result = result.replace("typeB", q(args[1]));
227223
}
228224
break;
229225

230226
case IProblem.LocalVariableIsNeverUsed:
231227
if (args.length > 0) {
232-
result = Language.text("editor.status.unused_variable");
233-
result = result.replace("varname", q(args[0]));
228+
result = Language.interpolate("editor.status.unused_variable", args[0]);
234229
}
235230
break;
236231

237232
case IProblem.UninitializedLocalVariable:
238233
if (args.length > 0) {
239-
result = Language.text("editor.status.uninitialized_variable");
240-
result = result.replace("varname", q(args[0]));
234+
result = Language.interpolate("editor.status.uninitialized_variable", args[0]);
241235
}
242236
break;
243237

244238
case IProblem.AssignmentHasNoEffect:
245239
if (args.length > 0) {
246-
result = Language.text("editor.status.no_effect_assignment");
247-
result = result.replace("varname", q(args[0]));
240+
result = Language.interpolate("editor.status.no_effect_assignment", args[0]);
248241
}
249242
break;
250243
}
@@ -257,51 +250,51 @@ public static String getSimplifiedErrorMessage(Problem problem) {
257250
/**
258251
* Converts java.lang.String into String, etc
259252
*/
260-
static private String getSimpleName(String inp) {
261-
if (inp.indexOf('.') < 0) {
262-
return inp;
263-
}
264-
String res = "";
265-
ArrayList<String> names = new ArrayList<String>();
266-
if (inp.indexOf(',') >= 0) {
267-
String arr[] = inp.split(",");
268-
for (int i = 0; i < arr.length; i++) {
269-
names.add(arr[i]);
270-
}
271-
} else {
272-
names.add(inp);
253+
static private String removePackagePrefixes(String input) {
254+
if (!input.contains(".")) {
255+
return input;
273256
}
274-
for (String n : names) {
275-
int x = n.lastIndexOf('.');
276-
if (x >= 0) {
277-
n = n.substring(x + 1, n.length());
257+
String[] names = PApplet.split(input, ',');
258+
// List<String> names = new ArrayList<String>();
259+
// if (inp.indexOf(',') >= 0) {
260+
// names.addAll(Arrays.asList(inp.split(",")));
261+
// } else {
262+
// names.add(inp);
263+
// }
264+
StringList result = new StringList();
265+
for (String name : names) {
266+
int dot = name.lastIndexOf('.');
267+
if (dot >= 0) {
268+
name = name.substring(dot + 1, name.length());
278269
}
279-
res = res + ", " + n;
270+
result.append(name);
280271
}
281-
return res.substring(2, res.length());
272+
return result.join(", ");
282273
}
283274

284275

285276
static private String getErrorMessageForBracket(char c) {
286277
switch (c) {
287-
case ';': return Language.text("editor.status.missing.semi_colon") + qs(";");
288-
case '[': return Language.text("editor.status.missing.open_sq_bracket") + qs("[");
289-
case ']': return Language.text("editor.status.missing.closing_sq_bracket") + qs("]");
290-
case '(': return Language.text("editor.status.missing.open_paren") + qs("(");
291-
case ')': return Language.text("editor.status.missing.close_paren") + qs(")");
292-
case '{': return Language.text("editor.status.missing.open_curly_bracket") + qs("{");
293-
case '}': return Language.text("editor.status.missing.closing_curly_bracket") + qs("}");
278+
case ';': return Language.text("editor.status.missing.semi_colon");
279+
case '[': return Language.text("editor.status.missing.open_sq_bracket");
280+
case ']': return Language.text("editor.status.missing.closing_sq_bracket");
281+
case '(': return Language.text("editor.status.missing.open_paren");
282+
case ')': return Language.text("editor.status.missing.close_paren");
283+
case '{': return Language.text("editor.status.missing.open_curly_bracket");
284+
case '}': return Language.text("editor.status.missing.closing_curly_bracket");
294285
}
295-
return Language.text("editor.status.missing.default") + qs(c);
286+
// This seems to be unreachable and wasn't in PDE.properties.
287+
// I've added it for 3.0a8, but that seems gross. [fry]
288+
return Language.interpolate("editor.status.missing.default", c);
296289
}
297290

298291

299-
static private final String q(Object quotable) {
300-
return "\"" + quotable + "\"";
301-
}
292+
// static private final String q(Object quotable) {
293+
// return "\"" + quotable + "\"";
294+
// }
302295

303296

304-
static private final String qs(Object quotable) {
305-
return " " + q(quotable);
306-
}
297+
// static private final String qs(Object quotable) {
298+
// return " " + q(quotable);
299+
// }
307300
}

todo.txt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ X Use system proxy by default
3939
X https://github.com/processing/processing/issues/1476
4040
X https://github.com/processing/processing/pull/3251
4141

42+
_ ErrorMessageSimplifier should use the language subst stuff
43+
_ also, shouldn't that be one text() method with different args?
44+
45+
_ "step" not working properly
46+
_ https://github.com/processing/processing/issues/3266
4247
_ "run sketches on display" not working in 3.0a7
4348
_ https://github.com/processing/processing/issues/3264
4449
_ "one file added to sketch" message when two files added
@@ -50,8 +55,6 @@ _ "Your sketch has been modified externally..." appears erroneously
5055
_ https://github.com/processing/processing/issues/3222
5156
_ add a preference for this while it's being debugged
5257
_ move to launch4j 3.7 http://launch4j.sourceforge.net/
53-
_ ErrorMessageSimplifier should use the language subst stuff
54-
_ also, shouldn't that be one text() method with different args?
5558
_ move processing-java inside the Java Mode?
5659
_ make a Tool that installs it for all platforms, not just OS X
5760
_ not really part of the 'build' anymore

0 commit comments

Comments
 (0)