finish cleaning up suggestions.txt handling and related code

This commit is contained in:
Ben Fry
2021-08-02 06:54:34 -04:00
parent 4bb9cd34f0
commit 6656ae211d
5 changed files with 29 additions and 68 deletions

View File

@@ -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<ImportStatement> 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;
}
}

View File

@@ -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<String> includedSuggestions = ConcurrentHashMap.newKeySet();
static private final Set<String> excludedSuggestions = ConcurrentHashMap.newKeySet();
private final Set<String> includedSuggestions = ConcurrentHashMap.newKeySet();
private final Set<String> 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"
);
};
}

View File

@@ -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;
}