From bd901c95bc945b7522330a81eba8be4a35f5f101 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Sun, 1 Aug 2021 18:31:43 -0400 Subject: [PATCH] further untangling of completion suggestions; yikes --- .../mode/java/CompletionGenerator.java | 6 +-- java/src/processing/mode/java/JavaMode.java | 38 +++++++++++++------ 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/java/src/processing/mode/java/CompletionGenerator.java b/java/src/processing/mode/java/CompletionGenerator.java index b530d7d9c..c3528854c 100644 --- a/java/src/processing/mode/java/CompletionGenerator.java +++ b/java/src/processing/mode/java/CompletionGenerator.java @@ -1305,13 +1305,13 @@ public class CompletionGenerator { if (isImported) return false; if (impName.startsWith("processing")) { - if (JavaMode.checkSuggestion("include", impName)) { + if (JavaMode.includeSuggestion(impName)) { return false; - } else if (JavaMode.checkSuggestion("exclude", impName)) { + } else if (JavaMode.excludeSuggestion(impName)) { return true; } } else if (impName.startsWith("java")) { - if (JavaMode.checkSuggestion("include", impName)) { + if (JavaMode.includeSuggestion(impName)) { return false; } } diff --git a/java/src/processing/mode/java/JavaMode.java b/java/src/processing/mode/java/JavaMode.java index 439c3edeb..1e2ac4d6b 100644 --- a/java/src/processing/mode/java/JavaMode.java +++ b/java/src/processing/mode/java/JavaMode.java @@ -29,6 +29,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import processing.app.*; import processing.app.ui.Editor; @@ -53,6 +54,7 @@ public class JavaMode extends Mode { // initLogger(); loadPreferences(); + loadSuggestionsMap(); } @@ -239,13 +241,26 @@ public class JavaMode extends Mode { * Stores the white list/black list of allowed/blacklisted imports. * These are defined in suggestions.txt in java mode folder. */ - static private final Map> suggestionsMap = new HashMap<>(); + static private final Set includedSuggestions = ConcurrentHashMap.newKeySet(); + static private final Set excludedSuggestions = ConcurrentHashMap.newKeySet(); + static boolean includeSuggestion(String impName) { + return includedSuggestions.contains(impName); + } + + + static boolean excludeSuggestion(String impName) { + return excludedSuggestions.contains(impName); + } + + + /* static boolean checkSuggestion(String mapName, String impName) { return suggestionsMap.containsKey(mapName) && suggestionsMap.get(mapName).contains(impName); } + */ public void loadPreferences() { @@ -264,8 +279,6 @@ public class JavaMode extends Mode { ccTriggerEnabled = Preferences.getBoolean(COMPLETION_TRIGGER_PREF); importSuggestEnabled = Preferences.getBoolean(SUGGEST_IMPORTS_PREF); inspectModeHotkeyEnabled = Preferences.getBoolean(INSPECT_MODE_HOTKEY_PREF); - - loadSuggestionsMap(); } @@ -294,21 +307,22 @@ public class JavaMode extends Mode { String[] lines = PApplet.loadStrings(suggestionsFile); if (lines != null) { for (String line : lines) { - if (!line.trim().startsWith("#")) { + line = line.trim(); + if (line.length() > 0 && !line.startsWith("#")) { int equals = line.indexOf('='); if (equals != -1) { - // Looks like multiple versions of the same key are possible, - // so can't just use our Settings class. String key = line.substring(0, equals).trim(); - String val = line.substring(equals + 1).trim(); + String value = line.substring(equals + 1).trim(); - if (suggestionsMap.containsKey(key)) { - suggestionsMap.get(key).add(val); + if (key.equals("include")) { + includedSuggestions.add(value); + } else if (key.equals("exclude")) { + excludedSuggestions.add(value); } else { - HashSet set = new HashSet<>(); - set.add(val); - suggestionsMap.put(key, set); + Messages.loge("Should be include or exclude: " + key); } + } else { + Messages.loge("Bad line found in suggestions file: " + line); } } }