From 6656ae211d6f15e5d30ebf6c24e497c996037aa8 Mon Sep 17 00:00:00 2001 From: Ben Fry Date: Mon, 2 Aug 2021 06:54:34 -0400 Subject: [PATCH] finish cleaning up suggestions.txt handling and related code --- .../mode/java/CompletionGenerator.java | 12 +++-- java/src/processing/mode/java/JavaMode.java | 33 ++++++++----- .../processing/mode/java/JavaTextArea.java | 3 +- java/suggestions.txt | 48 ------------------- todo.txt | 1 + 5 files changed, 29 insertions(+), 68 deletions(-) delete mode 100644 java/suggestions.txt diff --git a/java/src/processing/mode/java/CompletionGenerator.java b/java/src/processing/mode/java/CompletionGenerator.java index 82ae41b3d..0f9a03d62 100644 --- a/java/src/processing/mode/java/CompletionGenerator.java +++ b/java/src/processing/mode/java/CompletionGenerator.java @@ -64,8 +64,10 @@ import com.google.classpath.RegExpResourceFilter; @SuppressWarnings({ "unchecked" }) public class CompletionGenerator { + JavaMode mode; - public CompletionGenerator() { + public CompletionGenerator(JavaMode mode) { + this.mode = mode; //addCompletionPopupListner(); //loadJavaDoc(); } @@ -1285,7 +1287,7 @@ public class CompletionGenerator { } - static protected boolean ignorableSuggestionImport(PreprocSketch ps, String impName) { + protected boolean ignorableSuggestionImport(PreprocSketch ps, String impName) { String impNameLc = impName.toLowerCase(); List programImports = ps.programImports; @@ -1301,13 +1303,13 @@ public class CompletionGenerator { if (isImported) return false; if (impName.startsWith("processing")) { - if (JavaMode.includeSuggestion(impName)) { + if (mode.includeSuggestion(impName)) { return false; - } else if (JavaMode.excludeSuggestion(impName)) { + } else if (mode.excludeSuggestion(impName)) { return true; } } else if (impName.startsWith("java")) { - if (JavaMode.includeSuggestion(impName)) { + if (mode.includeSuggestion(impName)) { return false; } } diff --git a/java/src/processing/mode/java/JavaMode.java b/java/src/processing/mode/java/JavaMode.java index e0fe321f7..5f0d1bd00 100644 --- a/java/src/processing/mode/java/JavaMode.java +++ b/java/src/processing/mode/java/JavaMode.java @@ -33,7 +33,6 @@ import processing.app.ui.Editor; import processing.app.ui.EditorException; import processing.app.ui.EditorState; -import processing.core.PApplet; import processing.mode.java.runner.Runner; import processing.mode.java.tweak.SketchParser; @@ -49,7 +48,6 @@ public class JavaMode extends Mode { public JavaMode(Base base, File folder) { super(base, folder); -// initLogger(); loadPreferences(); loadSuggestionsMap(); } @@ -238,16 +236,16 @@ 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 Set includedSuggestions = ConcurrentHashMap.newKeySet(); - static private final Set excludedSuggestions = ConcurrentHashMap.newKeySet(); + private final Set includedSuggestions = ConcurrentHashMap.newKeySet(); + private final Set excludedSuggestions = ConcurrentHashMap.newKeySet(); - static boolean includeSuggestion(String impName) { + boolean includeSuggestion(String impName) { return includedSuggestions.contains(impName); } - static boolean excludeSuggestion(String impName) { + boolean excludeSuggestion(String impName) { return excludedSuggestions.contains(impName); } @@ -298,10 +296,15 @@ public class JavaMode extends Mode { } - // While not pretty, loading from a file, and the necessary error-handling - // is even uglier. And we're not modifying these externally anyway. private void loadSuggestionsMap() { - Collections.addAll(includedSuggestions, + Collections.addAll(includedSuggestions, getSuggestionIncludeList()); + Collections.addAll(excludedSuggestions, getSuggestionExcludeList()); + } + + + // broken out so that it can be overridden by Android, etc + protected String[] getSuggestionIncludeList() { + return new String[] { "processing.core.PApplet", "processing.core.PFont", "processing.core.PGraphics", @@ -336,10 +339,14 @@ public class JavaMode extends Mode { "java.util.HashMap", "java.io.PrintWriter", "java.lang.String" - ); + }; + } - Collections.addAll(excludedSuggestions, - "processing.core.PGraphicsRetina2D", + + // broken out so that it can be overridden by Android, etc + protected String[] getSuggestionExcludeList() { + return new String[] { + "processing.core.PGraphicsRetina2D", "processing.core.PShapeOBJ", "processing.core.PShapeSVG", "processing.data.Sort", @@ -348,7 +355,7 @@ public class JavaMode extends Mode { "processing.opengl.LinePath.PathIterator", "processing.opengl.LineStroker", "processing.opengl.PGraphicsOpenGL" - ); + }; } diff --git a/java/src/processing/mode/java/JavaTextArea.java b/java/src/processing/mode/java/JavaTextArea.java index 1d4d50bc0..0e3b9a315 100644 --- a/java/src/processing/mode/java/JavaTextArea.java +++ b/java/src/processing/mode/java/JavaTextArea.java @@ -52,8 +52,7 @@ public class JavaTextArea extends PdeTextArea { public JavaTextArea(TextAreaDefaults defaults, JavaEditor editor) { super(defaults, new JavaInputHandler(editor), editor); - suggestionGenerator = new CompletionGenerator(); - + suggestionGenerator = new CompletionGenerator((JavaMode) editor.getMode()); tweakMode = false; } diff --git a/java/suggestions.txt b/java/suggestions.txt deleted file mode 100644 index ae9f8642e..000000000 --- a/java/suggestions.txt +++ /dev/null @@ -1,48 +0,0 @@ -#List of suggestions to include/exclude in code completion - -#= - -include=processing.core.PApplet -include=processing.core.PFont -include=processing.core.PGraphics -include=processing.core.PImage -include=processing.core.PMatrix2D -include=processing.core.PMatrix3D -include=processing.core.PStyle -include=processing.core.PVector -include=processing.core.PShape -include=processing.core.PGraphicsJava2D -include=processing.core.PGraphics2D -include=processing.core.PGraphics3D -include=processing.data.FloatDict -include=processing.data.FloatList -include=processing.data.IntDict -include=processing.data.IntList -include=processing.data.JSONArray -include=processing.data.JSONObject -include=processing.data.StringDict -include=processing.data.StringList -include=processing.data.Table -include=processing.data.XML -include=processing.event.Event -include=processing.event.KeyEvent -include=processing.event.MouseEvent -include=processing.event.TouchEvent -include=processing.opengl.PShader -include=processing.opengl.PGL - -exclude=processing.core.PGraphicsRetina2D -exclude=processing.core.PShapeOBJ -exclude=processing.core.PShapeSVG -exclude=processing.data.Sort -exclude=processing.opengl.FrameBuffer -exclude=processing.opengl.LinePath -exclude=processing.opengl.LinePath.PathIterator -exclude=processing.opengl.LineStroker -exclude=processing.opengl.PGraphicsOpenGL - -include=java.util.ArrayList -include=java.io.BufferedReader -include=java.util.HashMap -include=java.io.PrintWriter -include=java.lang.String \ No newline at end of file diff --git a/todo.txt b/todo.txt index 8c1ae9ba7..34d7e38e3 100755 --- a/todo.txt +++ b/todo.txt @@ -3,6 +3,7 @@ X really chatty console messages for people with old settings directories X ignore 'debug' entry in prefs dir if it's a leftover DebugMode directory X IDE cursor position on Windows goes weird if display scaling used X https://github.com/processing/processing4/issues/226 +X cleaning up suggestions.txt handling and related code Sam updates