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

Clean up ErrorMessageSimplifier · SourceCode/processing@c607a0d · GitHub

Repository navigation

Commit c607a0d

Browse files
committed
Clean up ErrorMessageSimplifier
Remove weird unused thread-spawning constructor Accept IProblem instead of whole JavaProblem Move fallback process() from JavaProblem to EMSimplifier as a default case Add debug switch and move debug logging into if blocks
1 parent c580d99 commit c607a0d

2 files changed

Lines changed: 40 additions & 53 deletions

File tree

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

Lines changed: 39 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
import java.lang.reflect.Field;
2424
import java.lang.reflect.Modifier;
2525
import java.util.TreeMap;
26+
import java.util.regex.Matcher;
27+
import java.util.regex.Pattern;
2628

2729
import org.eclipse.jdt.core.compiler.IProblem;
2830
import org.eclipse.jdt.internal.compiler.problem.DefaultProblem;
2931

3032
import processing.app.Language;
33+
import processing.app.Messages;
3134
import processing.core.PApplet;
3235
import processing.data.StringList;
3336

@@ -42,25 +45,20 @@ public class ErrorMessageSimplifier {
4245
*/
4346
private static TreeMap<Integer, String> constantsMap;
4447

48+
private static final boolean DEBUG = false;
4549

46-
public ErrorMessageSimplifier() {
47-
48-
new Thread() {
49-
public void run() {
50-
prepareConstantsList();
51-
}
52-
}.start();
53-
}
54-
50+
private static final Pattern tokenRegExp = Pattern.compile("\\b token\\b");
5551

5652
private static void prepareConstantsList() {
57-
constantsMap = new TreeMap<Integer, String>();
53+
constantsMap = new TreeMap<>();
5854
Class<DefaultProblem> probClass = DefaultProblem.class;
5955
Field f[] = probClass.getFields();
6056
for (Field field : f) {
6157
if (Modifier.isStatic(field.getModifiers()))
6258
try {
63-
//System.out.println(field.getName() + " :" + field.get(null));
59+
if (DEBUG) {
60+
Messages.log(field.getName() + " :" + field.get(null));
61+
}
6462
Object val = field.get(null);
6563
if (val instanceof Integer) {
6664
constantsMap.put((Integer) (val), field.getName());
@@ -70,7 +68,9 @@ private static void prepareConstantsList() {
7068
break;
7169
}
7270
}
73-
//System.out.println("Total items: " + constantsMap.size());
71+
if (DEBUG) {
72+
Messages.log("Total items: " + constantsMap.size());
73+
}
7474
}
7575

7676

@@ -85,17 +85,19 @@ public static String getIDName(int id) {
8585
/**
8686
* Tones down the jargon in the ecj reported errors.
8787
*/
88-
public static String getSimplifiedErrorMessage(JavaProblem problem) {
89-
if (problem == null) return null;
88+
public static String getSimplifiedErrorMessage(IProblem iprob) {
89+
if (iprob == null) return null;
9090

91-
IProblem iprob = problem.getIProblem();
9291
String args[] = iprob.getArguments();
93-
// Base.log("Simplifying message: " + problem.getMessage() + " ID: "
94-
// + getIDName(iprob.getID()));
95-
// Base.log("Arg count: " + args.length);
96-
// for (int i = 0; i < args.length; i++) {
97-
// Base.log("Arg " + args[i]);
98-
// }
92+
93+
if (DEBUG) {
94+
Messages.log("Simplifying message: " + iprob.getMessage() +
95+
" ID: " + getIDName(iprob.getID()));
96+
Messages.log("Arg count: " + args.length);
97+
for (String arg : args) {
98+
Messages.log("Arg " + arg);
99+
}
100+
}
99101

100102
String result = null;
101103

@@ -259,10 +261,24 @@ public static String getSimplifiedErrorMessage(JavaProblem problem) {
259261
if (args.length > 0) {
260262
result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]);
261263
}
264+
break;
265+
266+
default:
267+
String message = iprob.getMessage();
268+
if (message != null) {
269+
// Remove all instances of token
270+
// "Syntax error on token 'blah', delete this token"
271+
Matcher matcher = tokenRegExp.matcher(message);
272+
message = matcher.replaceAll("");
273+
result = message;
274+
}
275+
}
276+
277+
if (DEBUG) {
278+
Messages.log("Simplified Error Msg: " + result);
262279
}
263280

264-
//log("Simplified Error Msg: " + result);
265-
return (result == null) ? problem.getMessage() : result;
281+
return result;
266282
}
267283

268284

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

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020

2121
package processing.mode.java.pdex;
2222

23-
import java.util.regex.Matcher;
24-
import java.util.regex.Pattern;
25-
2623
import org.eclipse.jdt.core.compiler.IProblem;
2724

2825
import processing.app.Problem;
@@ -83,9 +80,7 @@ else if(iProblem.isWarning()) {
8380
}
8481
this.tabIndex = tabIndex;
8582
this.lineNumber = lineNumber;
86-
this.message = process(iProblem);
87-
this.message = ErrorMessageSimplifier.getSimplifiedErrorMessage(this);
88-
//ErrorMessageSimplifier.getSimplifiedErrorMessage(this);
83+
this.message = ErrorMessageSimplifier.getSimplifiedErrorMessage(iProblem);
8984
}
9085

9186
public void setPDEOffsets(int startOffset, int stopOffset){
@@ -157,30 +152,6 @@ public void setImportSuggestions(String[] a) {
157152
importSuggestions = a;
158153
}
159154

160-
private static final Pattern tokenRegExp = Pattern.compile("\\b token\\b");
161-
162-
public static String process(IProblem problem) {
163-
return process(problem.getMessage());
164-
}
165-
166-
/**
167-
* Processes error messages and attempts to make them a bit more english like.
168-
* Currently performs:
169-
* <li>Remove all instances of token. "Syntax error on token 'blah', delete this token"
170-
* becomes "Syntax error on 'blah', delete this"
171-
* @param message - The message to be processed
172-
* @return String - The processed message
173-
*/
174-
public static String process(String message) {
175-
// Remove all instances of token
176-
// "Syntax error on token 'blah', delete this token"
177-
if(message == null) return null;
178-
Matcher matcher = tokenRegExp.matcher(message);
179-
message = matcher.replaceAll("");
180-
181-
return message;
182-
}
183-
184155
// Split camel case words into separate words.
185156
// "VaraibleDeclaration" becomes "Variable Declaration"
186157
// But sadly "PApplet" become "P Applet" and so on.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL