|
20 | 20 |
|
21 | 21 | package processing.mode.java.pdex; |
22 | 22 |
|
| 23 | +import java.util.Arrays; |
| 24 | + |
23 | 25 | import org.eclipse.jdt.core.compiler.IProblem; |
| 26 | +import static org.eclipse.jdt.core.compiler.IProblem.*; |
24 | 27 |
|
25 | 28 | import processing.app.Problem; |
26 | 29 |
|
@@ -53,35 +56,95 @@ public class JavaProblem implements Problem { |
53 | 56 | */ |
54 | 57 | private int type; |
55 | 58 |
|
| 59 | + /** |
| 60 | + * Priority: bigger = higher. Currently 7 to 10 for errors, |
| 61 | + * 4 for warning. |
| 62 | + * <p> |
| 63 | + * The logic of the numbers in the priorityN arrays is that if ECJ wants a |
| 64 | + * token got rid of entirely it's most likely the root of the problem. If it |
| 65 | + * wants more tokens, that might have been caused by an unterminated string |
| 66 | + * or something but it's also likely to be the “real” error. Only if the |
| 67 | + * syntax is good are mismatched argument lists and so on of any real |
| 68 | + * significance. These rankings are entirely made up so can be changed to |
| 69 | + * support any other plausible scenario. |
| 70 | + */ |
| 71 | + private int priority; |
| 72 | + |
| 73 | + static private final int[] priority10 = { |
| 74 | + ParsingError, |
| 75 | + ParsingErrorDeleteToken, |
| 76 | + ParsingErrorDeleteTokens, |
| 77 | + ParsingErrorInvalidToken, |
| 78 | + ParsingErrorMergeTokens, |
| 79 | + ParsingErrorMisplacedConstruct, |
| 80 | + ParsingErrorNoSuggestion, |
| 81 | + ParsingErrorNoSuggestionForTokens, |
| 82 | + ParsingErrorOnKeyword, |
| 83 | + ParsingErrorOnKeywordNoSuggestion, |
| 84 | + ParsingErrorReplaceTokens, |
| 85 | + ParsingErrorUnexpectedEOF |
| 86 | + }; |
| 87 | + static private final int[] priority9 = { |
| 88 | + InvalidCharacterConstant, |
| 89 | + UnterminatedString |
| 90 | + }; |
| 91 | + static private final int[] priority8 = { |
| 92 | + ParsingErrorInsertToComplete, |
| 93 | + ParsingErrorInsertToCompletePhrase, |
| 94 | + ParsingErrorInsertToCompleteScope, |
| 95 | + ParsingErrorInsertTokenAfter, |
| 96 | + ParsingErrorInsertTokenBefore, |
| 97 | + }; |
| 98 | + // Sorted so I can do a one-line binary search later. |
| 99 | + static { |
| 100 | + Arrays.sort(priority10); |
| 101 | + Arrays.sort(priority9); |
| 102 | + Arrays.sort(priority8); |
| 103 | + } |
| 104 | + |
56 | 105 | /** |
57 | 106 | * If the error is a 'cannot find type' contains the list of suggested imports |
58 | 107 | */ |
59 | 108 | private String[] importSuggestions; |
60 | 109 |
|
61 | 110 | public static final int ERROR = 1, WARNING = 2; |
62 | 111 |
|
63 | | - public JavaProblem(String message, int type, int tabIndex, int lineNumber) { |
| 112 | + public JavaProblem(String message, int type, int tabIndex, int lineNumber, int priority) { |
64 | 113 | this.message = message; |
65 | 114 | this.type = type; |
66 | 115 | this.tabIndex = tabIndex; |
67 | 116 | this.lineNumber = lineNumber; |
| 117 | + this.priority = priority; |
68 | 118 | } |
69 | 119 |
|
70 | 120 | /** |
71 | 121 | * |
72 | 122 | * @param iProblem - The IProblem which is being wrapped |
73 | 123 | * @param tabIndex - The tab number to which the error belongs to |
74 | 124 | * @param lineNumber - Line number(pde code) of the error |
| 125 | + * @param badCode - The code iProblem refers to. |
75 | 126 | */ |
76 | | - public static JavaProblem fromIProblem(IProblem iProblem, int tabIndex, int lineNumber) { |
| 127 | + public static JavaProblem fromIProblem(IProblem iProblem, |
| 128 | + int tabIndex, int lineNumber, String badCode) { |
77 | 129 | int type = 0; |
78 | | - if(iProblem.isError()) { |
| 130 | + int priority = 0; |
| 131 | + if (iProblem.isError()) { |
79 | 132 | type = ERROR; |
| 133 | + if (Arrays.binarySearch(priority10, iProblem.getID()) >= 0) { |
| 134 | + priority = 10; |
| 135 | + } else if (Arrays.binarySearch(priority9, iProblem.getID()) >= 0) { |
| 136 | + priority = 9; |
| 137 | + } else if (Arrays.binarySearch(priority8, iProblem.getID()) >= 0) { |
| 138 | + priority = 8; |
| 139 | + } else { |
| 140 | + priority = 7; |
| 141 | + } |
80 | 142 | } else if (iProblem.isWarning()) { |
81 | 143 | type = WARNING; |
| 144 | + priority = 4; |
82 | 145 | } |
83 | | - String message = ErrorMessageSimplifier.getSimplifiedErrorMessage(iProblem); |
84 | | - return new JavaProblem(message, type, tabIndex, lineNumber); |
| 146 | + String message = ErrorMessageSimplifier.getSimplifiedErrorMessage(iProblem, badCode); |
| 147 | + return new JavaProblem(message, type, tabIndex, lineNumber, priority); |
85 | 148 | } |
86 | 149 |
|
87 | 150 | public void setPDEOffsets(int startOffset, int stopOffset){ |
@@ -132,6 +195,10 @@ public void setImportSuggestions(String[] a) { |
132 | 195 | importSuggestions = a; |
133 | 196 | } |
134 | 197 |
|
| 198 | + public int getPriority() { |
| 199 | + return priority; |
| 200 | + } |
| 201 | + |
135 | 202 | @Override |
136 | 203 | public String toString() { |
137 | 204 | return "TAB " + tabIndex + ",LN " + lineNumber + "LN START OFF: " |
|
0 commit comments