| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent c580d99 commit c607a0d
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,11 +23,14 @@ | |||
| 23 | 23 | import java.lang.reflect.Field; | |
| 24 | 24 | import java.lang.reflect.Modifier; | |
| 25 | 25 | import java.util.TreeMap; | |
| 26 | + import java.util.regex.Matcher; | ||
| 27 | + import java.util.regex.Pattern; | ||
| 26 | 28 | ||
| 27 | 29 | import org.eclipse.jdt.core.compiler.IProblem; | |
| 28 | 30 | import org.eclipse.jdt.internal.compiler.problem.DefaultProblem; | |
| 29 | 31 | ||
| 30 | 32 | import processing.app.Language; | |
| 33 | + import processing.app.Messages; | ||
| 31 | 34 | import processing.core.PApplet; | |
| 32 | 35 | import processing.data.StringList; | |
| 33 | 36 | ||
@@ -42,25 +45,20 @@ public class ErrorMessageSimplifier { | |||
| 42 | 45 | */ | |
| 43 | 46 | private static TreeMap<Integer, String> constantsMap; | |
| 44 | 47 | ||
| 48 | + private static final boolean DEBUG = false; | ||
| 45 | 49 | ||
| 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"); | ||
| 55 | 51 | ||
| 56 | 52 | private static void prepareConstantsList() { | |
| 57 | - constantsMap = new TreeMap<Integer, String>(); | ||
| 53 | + constantsMap = new TreeMap<>(); | ||
| 58 | 54 | Class<DefaultProblem> probClass = DefaultProblem.class; | |
| 59 | 55 | Field f[] = probClass.getFields(); | |
| 60 | 56 | for (Field field : f) { | |
| 61 | 57 | if (Modifier.isStatic(field.getModifiers())) | |
| 62 | 58 | try { | |
| 63 | - //System.out.println(field.getName() + " :" + field.get(null)); | ||
| 59 | + if (DEBUG) { | ||
| 60 | + Messages.log(field.getName() + " :" + field.get(null)); | ||
| 61 | + } | ||
| 64 | 62 | Object val = field.get(null); | |
| 65 | 63 | if (val instanceof Integer) { | |
| 66 | 64 | constantsMap.put((Integer) (val), field.getName()); | |
@@ -70,7 +68,9 @@ private static void prepareConstantsList() { | |||
| 70 | 68 | break; | |
| 71 | 69 | } | |
| 72 | 70 | } | |
| 73 | - //System.out.println("Total items: " + constantsMap.size()); | ||
| 71 | + if (DEBUG) { | ||
| 72 | + Messages.log("Total items: " + constantsMap.size()); | ||
| 73 | + } | ||
| 74 | 74 | } | |
| 75 | 75 | ||
| 76 | 76 | ||
@@ -85,17 +85,19 @@ public static String getIDName(int id) { | |||
| 85 | 85 | /** | |
| 86 | 86 | * Tones down the jargon in the ecj reported errors. | |
| 87 | 87 | */ | |
| 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; | ||
| 90 | 90 | ||
| 91 | - IProblem iprob = problem.getIProblem(); | ||
| 92 | 91 | 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 | + } | ||
| 99 | 101 | ||
| 100 | 102 | String result = null; | |
| 101 | 103 | ||
@@ -259,10 +261,24 @@ public static String getSimplifiedErrorMessage(JavaProblem problem) { | |||
| 259 | 261 | if (args.length > 0) { | |
| 260 | 262 | result = Language.interpolate("editor.status.hiding_enclosing_type", args[0]); | |
| 261 | 263 | } | |
| 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); | ||
| 262 | 279 | } | |
| 263 | 280 | ||
| 264 | - //log("Simplified Error Msg: " + result); | ||
| 265 | - return (result == null) ? problem.getMessage() : result; | ||
| 281 | + return result; | ||
| 266 | 282 | } | |
| 267 | 283 | ||
| 268 | 284 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -20,9 +20,6 @@ | |||
| 20 | 20 | ||
| 21 | 21 | package processing.mode.java.pdex; | |
| 22 | 22 | ||
| 23 | - import java.util.regex.Matcher; | ||
| 24 | - import java.util.regex.Pattern; | ||
| 25 | - | ||
| 26 | 23 | import org.eclipse.jdt.core.compiler.IProblem; | |
| 27 | 24 | ||
| 28 | 25 | import processing.app.Problem; | |
@@ -83,9 +80,7 @@ else if(iProblem.isWarning()) { | |||
| 83 | 80 | } | |
| 84 | 81 | this.tabIndex = tabIndex; | |
| 85 | 82 | this.lineNumber = lineNumber; | |
| 86 | - this.message = process(iProblem); | ||
| 87 | - this.message = ErrorMessageSimplifier.getSimplifiedErrorMessage(this); | ||
| 88 | - //ErrorMessageSimplifier.getSimplifiedErrorMessage(this); | ||
| 83 | + this.message = ErrorMessageSimplifier.getSimplifiedErrorMessage(iProblem); | ||
| 89 | 84 | } | |
| 90 | 85 | ||
| 91 | 86 | public void setPDEOffsets(int startOffset, int stopOffset){ | |
@@ -157,30 +152,6 @@ public void setImportSuggestions(String[] a) { | |||
| 157 | 152 | importSuggestions = a; | |
| 158 | 153 | } | |
| 159 | 154 | ||
| 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 | - | ||
| 184 | 155 | // Split camel case words into separate words. | |
| 185 | 156 | // "VaraibleDeclaration" becomes "Variable Declaration" | |
| 186 | 157 | // But sadly "PApplet" become "P Applet" and so on. | |
| Back | FazBrowse Home | New Git URL |
0 commit comments