Don't cache search classpath, only build it when looking for a class

Fixes #4748

Libraries imported in opened sketches will be still locked by latest
preprocessed CompilationUnit. Otherwise we would have to copy library
jars somewhere else so they can be available to CompilationUnit while
Contribution Manager updates original unlocked jars.
This commit is contained in:
Jakub Valtar
2016-12-18 00:36:22 +01:00
parent b72a39564b
commit 0a02898ff1
3 changed files with 12 additions and 8 deletions

View File

@@ -1,6 +1,7 @@
package processing.mode.java.pdex;
import com.google.classpath.ClassPath;
import com.google.classpath.ClassPathFactory;
import com.google.classpath.RegExpResourceFilter;
import org.eclipse.jdt.core.compiler.IProblem;
@@ -44,6 +45,7 @@ import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@@ -1106,6 +1108,8 @@ public class PDEX {
}
}
AtomicReference<ClassPath> searchClassPath = new AtomicReference<>(null);
if (problems.isEmpty()) {
List<Problem> cuProblems = Arrays.stream(iproblems)
// Filter Warnings if they are not enabled
@@ -1129,7 +1133,8 @@ public class PDEX {
// Handle import suggestions
if (JavaMode.importSuggestEnabled && isUndefinedTypeProblem(iproblem)) {
ClassPath cp = ps.searchClassPath;
ClassPath cp = searchClassPath.updateAndGet(prev -> prev != null ?
prev : new ClassPathFactory().createFromPaths(ps.searchClassPathArray));
String[] s = suggCache.computeIfAbsent(iproblem.getArguments()[0],
name -> getImportSuggestions(cp, name));
p.setImportSuggestions(s);

View File

@@ -26,7 +26,7 @@ public class PreprocessedSketch {
public final ClassPath classPath;
public final URLClassLoader classLoader;
public final ClassPath searchClassPath;
public final String[] searchClassPathArray;
public final int[] tabStartOffsets;
@@ -206,7 +206,7 @@ public class PreprocessedSketch {
public ClassPath classPath;
public URLClassLoader classLoader;
public ClassPath searchClassPath;
public String[] searchClassPathArray;
public int[] tabStartOffsets = new int[0];
@@ -242,7 +242,7 @@ public class PreprocessedSketch {
classPath = b.classPath;
classLoader = b.classLoader;
searchClassPath = b.searchClassPath;
searchClassPathArray = b.searchClassPathArray;
tabStartOffsets = b.tabStartOffsets;

View File

@@ -341,7 +341,7 @@ public class PreprocessingService {
boolean rebuildClassPath = reloadCodeFolder || rebuildLibraryClassPath ||
prevResult.classLoader == null || prevResult.classPath == null ||
prevResult.classPathArray == null || prevResult.searchClassPath == null;
prevResult.classPathArray == null || prevResult.searchClassPathArray == null;
if (reloadCodeFolder) {
codeFolderClassPath = buildCodeFolderClassPath(sketch);
@@ -381,13 +381,12 @@ public class PreprocessingService {
searchClassPath.addAll(coreLibraryClassPath);
searchClassPath.addAll(codeFolderClassPath);
String[] searchClassPathArray = searchClassPath.stream().toArray(String[]::new);
result.searchClassPath = classPathFactory.createFromPaths(searchClassPathArray);
result.searchClassPathArray = searchClassPath.stream().toArray(String[]::new);
}
} else {
result.classLoader = prevResult.classLoader;
result.classPath = prevResult.classPath;
result.searchClassPath = prevResult.searchClassPath;
result.searchClassPathArray = prevResult.searchClassPathArray;
result.classPathArray = prevResult.classPathArray;
}
}