mirror of
https://github.com/processing/processing4.git
synced 2026-02-04 06:09:17 +01:00
ECS: import suggestions
- search classpath should be different than sketch classpath (WIP) - looks for inner classes - looks for each class only once and reuses the result
This commit is contained in:
@@ -99,8 +99,8 @@ import processing.app.Util;
|
||||
import processing.app.syntax.JEditTextArea;
|
||||
import processing.app.ui.EditorStatus;
|
||||
import processing.app.ui.Toolkit;
|
||||
import processing.core.PApplet;
|
||||
import processing.mode.java.JavaEditor;
|
||||
import processing.mode.java.JavaMode;
|
||||
import processing.mode.java.preproc.PdePreprocessor;
|
||||
|
||||
import com.google.classpath.ClassPath;
|
||||
@@ -2485,20 +2485,54 @@ public class ASTGenerator {
|
||||
return null;
|
||||
}
|
||||
|
||||
log("Looking for class " + className);
|
||||
RegExpResourceFilter regf = new RegExpResourceFilter(Pattern.compile(".*"),
|
||||
Pattern.compile(className + ".class",
|
||||
Pattern.CASE_INSENSITIVE));
|
||||
// TODO once saw NPE here...possible for classPath to be null? [fry 150808]
|
||||
String[] resources = classPath.findResources("", regf);
|
||||
List<String> candidates = new ArrayList<>();
|
||||
Collections.addAll(candidates, resources);
|
||||
// TODO: make sure search class path is complete,
|
||||
// prepare it beforehand and reuse it
|
||||
//
|
||||
// this in not the same as sketch class path!
|
||||
// should include:
|
||||
// - all contributed libraries
|
||||
// - core libraries
|
||||
// - code folder
|
||||
// - mode search path
|
||||
// - Java classpath
|
||||
|
||||
// log("Couldn't find import for class " + className);
|
||||
log("Looking for class " + className);
|
||||
RegExpResourceFilter regf =
|
||||
new RegExpResourceFilter(Pattern.compile(".*"),
|
||||
Pattern.compile("(.*\\$)?" + className + "\\.class",
|
||||
Pattern.CASE_INSENSITIVE));
|
||||
// TODO once saw NPE here...possible for classPath to be null? [fry 150808]
|
||||
List<String> candidates = new ArrayList<>();
|
||||
|
||||
|
||||
{ // Mode search path
|
||||
String searchPath = ((JavaMode) editor.getMode()).getSearchPath();
|
||||
|
||||
// Make sure class path does not contain empty string (home dir)
|
||||
String[] paths = searchPath.split(File.pathSeparator);
|
||||
|
||||
List<String> entries = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i < paths.length; i++) {
|
||||
String path = paths[i];
|
||||
if (path != null && !path.trim().isEmpty()) {
|
||||
entries.add(path);
|
||||
}
|
||||
}
|
||||
|
||||
String[] pathArray = entries.toArray(new String[entries.size()]);
|
||||
classPath = factory.createFromPaths(pathArray);
|
||||
|
||||
String[] resources = classPath.findResources("", regf);
|
||||
for (String res : resources) {
|
||||
candidates.add(res);
|
||||
log("Res: " + res);
|
||||
}
|
||||
}
|
||||
|
||||
for (Library lib : editor.getMode().contribLibraries) {
|
||||
ClassPath cp = factory.createFromPath(lib.getClassPath());
|
||||
resources = cp.findResources("", regf);
|
||||
String[] resources = cp.findResources("", regf);
|
||||
for (String res : resources) {
|
||||
candidates.add(res);
|
||||
log("Res: " + res);
|
||||
@@ -2510,24 +2544,19 @@ public class ASTGenerator {
|
||||
// get a list of .jar files in the "code" folder
|
||||
// (class files in subfolders should also be picked up)
|
||||
ClassPath cp = factory.createFromPath(Util.contentsToClassPath(codeFolder));
|
||||
resources = cp.findResources("", regf);
|
||||
String[] resources = cp.findResources("", regf);
|
||||
for (String res : resources) {
|
||||
candidates.add(res);
|
||||
log("Res: " + res);
|
||||
}
|
||||
}
|
||||
|
||||
resources = new String[candidates.size()];
|
||||
String[] resources = new String[candidates.size()];
|
||||
for (int i = 0; i < resources.length; i++) {
|
||||
resources[i] = candidates.get(i).replace('/', '.')
|
||||
resources[i] = candidates.get(i).replace('/', '.').replace('$', '.')
|
||||
.substring(0, candidates.get(i).length() - 6);
|
||||
}
|
||||
|
||||
// ArrayList<String> ans = new ArrayList<String>();
|
||||
// for (int i = 0; i < resources.length; i++) {
|
||||
// ans.add(resources[i]);
|
||||
// }
|
||||
|
||||
return resources;
|
||||
}
|
||||
|
||||
|
||||
@@ -860,9 +860,8 @@ public class ErrorCheckerService {
|
||||
ErrorTable table = editor.getErrorTable();
|
||||
table.clearRows();
|
||||
|
||||
// String[][] errorData = new String[problemsList.size()][3];
|
||||
// int index = 0;
|
||||
// for (int i = 0; i < problemsList.size(); i++) {
|
||||
Map<String, String[]> suggestions = new HashMap<>();
|
||||
|
||||
Sketch sketch = editor.getSketch();
|
||||
for (Problem p : problems) {
|
||||
String message = p.getMessage();
|
||||
@@ -871,14 +870,15 @@ public class ErrorCheckerService {
|
||||
String[] args = p.getIProblem().getArguments();
|
||||
if (args.length > 0) {
|
||||
String missingClass = args[0];
|
||||
String[] si;
|
||||
synchronized (astGenerator) {
|
||||
si = astGenerator.getSuggestImports(missingClass);
|
||||
String[] si = suggestions.get(missingClass);
|
||||
if (si == null) {
|
||||
synchronized (astGenerator) {
|
||||
si = astGenerator.getSuggestImports(missingClass);
|
||||
}
|
||||
suggestions.put(missingClass, si);
|
||||
}
|
||||
if (si != null && si.length > 0) {
|
||||
p.setImportSuggestions(si);
|
||||
// errorData[index][0] = "<html>" + p.getMessage() +
|
||||
// " (<font color=#0000ff><u>Import Suggestions available</u></font>)</html>";
|
||||
message += " (double-click for suggestions)";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user