|
29 | 29 | import java.util.HashSet; |
30 | 30 | import java.util.Map; |
31 | 31 | import java.util.Set; |
| 32 | +import java.util.concurrent.ConcurrentHashMap; |
32 | 33 |
|
33 | 34 | import processing.app.*; |
34 | 35 | import processing.app.ui.Editor; |
@@ -53,6 +54,7 @@ public JavaMode(Base base, File folder) { |
53 | 54 |
|
54 | 55 | // initLogger(); |
55 | 56 | loadPreferences(); |
| 57 | + loadSuggestionsMap(); |
56 | 58 | } |
57 | 59 |
|
58 | 60 |
|
@@ -239,13 +241,26 @@ public String getSearchPath() { |
239 | 241 | * Stores the white list/black list of allowed/blacklisted imports. |
240 | 242 | * These are defined in suggestions.txt in java mode folder. |
241 | 243 | */ |
242 | | - static private final Map<String, Set<String>> suggestionsMap = new HashMap<>(); |
| 244 | + static private final Set<String> includedSuggestions = ConcurrentHashMap.newKeySet(); |
| 245 | + static private final Set<String> excludedSuggestions = ConcurrentHashMap.newKeySet(); |
| 246 | + |
243 | 247 |
|
| 248 | + static boolean includeSuggestion(String impName) { |
| 249 | + return includedSuggestions.contains(impName); |
| 250 | + } |
244 | 251 |
|
| 252 | + |
| 253 | + static boolean excludeSuggestion(String impName) { |
| 254 | + return excludedSuggestions.contains(impName); |
| 255 | + } |
| 256 | + |
| 257 | + |
| 258 | + /* |
245 | 259 | static boolean checkSuggestion(String mapName, String impName) { |
246 | 260 | return suggestionsMap.containsKey(mapName) && |
247 | 261 | suggestionsMap.get(mapName).contains(impName); |
248 | 262 | } |
| 263 | + */ |
249 | 264 |
|
250 | 265 |
|
251 | 266 | public void loadPreferences() { |
@@ -264,8 +279,6 @@ public void loadPreferences() { |
264 | 279 | ccTriggerEnabled = Preferences.getBoolean(COMPLETION_TRIGGER_PREF); |
265 | 280 | importSuggestEnabled = Preferences.getBoolean(SUGGEST_IMPORTS_PREF); |
266 | 281 | inspectModeHotkeyEnabled = Preferences.getBoolean(INSPECT_MODE_HOTKEY_PREF); |
267 | | - |
268 | | - loadSuggestionsMap(); |
269 | 282 | } |
270 | 283 |
|
271 | 284 |
|
@@ -294,21 +307,22 @@ private void loadSuggestionsMap() { |
294 | 307 | String[] lines = PApplet.loadStrings(suggestionsFile); |
295 | 308 | if (lines != null) { |
296 | 309 | for (String line : lines) { |
297 | | - if (!line.trim().startsWith("#")) { |
| 310 | + line = line.trim(); |
| 311 | + if (line.length() > 0 && !line.startsWith("#")) { |
298 | 312 | int equals = line.indexOf('='); |
299 | 313 | if (equals != -1) { |
300 | | - // Looks like multiple versions of the same key are possible, |
301 | | - // so can't just use our Settings class. |
302 | 314 | String key = line.substring(0, equals).trim(); |
303 | | - String val = line.substring(equals + 1).trim(); |
| 315 | + String value = line.substring(equals + 1).trim(); |
304 | 316 |
|
305 | | - if (suggestionsMap.containsKey(key)) { |
306 | | - suggestionsMap.get(key).add(val); |
| 317 | + if (key.equals("include")) { |
| 318 | + includedSuggestions.add(value); |
| 319 | + } else if (key.equals("exclude")) { |
| 320 | + excludedSuggestions.add(value); |
307 | 321 | } else { |
308 | | - HashSet<String> set = new HashSet<>(); |
309 | | - set.add(val); |
310 | | - suggestionsMap.put(key, set); |
| 322 | + Messages.loge("Should be include or exclude: " + key); |
311 | 323 | } |
| 324 | + } else { |
| 325 | + Messages.loge("Bad line found in suggestions file: " + line); |
312 | 326 | } |
313 | 327 | } |
314 | 328 | } |
|