2222
2323import java .lang .reflect .Field ;
2424import java .lang .reflect .Modifier ;
25- import java .util .ArrayList ;
2625import java .util .TreeMap ;
2726
2827import org .eclipse .jdt .core .compiler .IProblem ;
2928import org .eclipse .jdt .internal .compiler .problem .DefaultProblem ;
3029
3130import processing .app .Language ;
31+ import processing .core .PApplet ;
32+ import processing .data .StringList ;
3233
3334
3435public 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}
0 commit comments