Remove analyzeProjectWithCache with caching on project. It's used nowhere, gives cycles in resolve and produce second copy of binding context.
KT-1792 UI freeze and AssertionError in log #KT-1792 fixed
This commit is contained in:
@@ -129,8 +129,8 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Collection<FqName> getFQNamesByName(@NotNull final String name, @NotNull GlobalSearchScope scope) {
|
||||
BindingContext context = WholeProjectAnalyzerFacade.analyzeProjectWithCache(project, scope).getBindingContext();
|
||||
public Collection<FqName> getFQNamesByName(@NotNull final String name, JetFile file, @NotNull GlobalSearchScope scope) {
|
||||
BindingContext context = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file).getBindingContext();
|
||||
return Collections2.filter(context.getKeys(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR), new Predicate<FqName>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable FqName fqName) {
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.plugin.project;
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.util.CachedValue;
|
||||
@@ -111,47 +110,4 @@ public final class AnalyzerFacadeWithCache {
|
||||
DiagnosticUtils.throwIfRunningOnServer(e);
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
/**
|
||||
* Analyze project with string cache for the whole project. All given files will be analyzed only for descriptors.
|
||||
*/
|
||||
@NotNull
|
||||
public static AnalyzeExhaust analyzeProjectWithCache(@NotNull final Project project, @NotNull final Collection<JetFile> files) {
|
||||
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
|
||||
synchronized (lock) {
|
||||
CachedValue<AnalyzeExhaust> bindingContextCachedValue = project.getUserData(ANALYZE_EXHAUST);
|
||||
if (bindingContextCachedValue == null) {
|
||||
bindingContextCachedValue =
|
||||
CachedValuesManager.getManager(project).createCachedValue(new CachedValueProvider<AnalyzeExhaust>() {
|
||||
@Override
|
||||
public Result<AnalyzeExhaust> compute() {
|
||||
try {
|
||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeProvider.getAnalyzerFacadeForProject(project)
|
||||
.analyzeFiles(project,
|
||||
files,
|
||||
Predicates.<PsiFile>alwaysFalse(),
|
||||
JetControlFlowDataTraceFactory.EMPTY);
|
||||
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
handleError(e);
|
||||
return emptyExhaust();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Result<AnalyzeExhaust> emptyExhaust() {
|
||||
BindingTraceContext bindingTraceContext = new BindingTraceContext();
|
||||
AnalyzeExhaust analyzeExhaust = new AnalyzeExhaust(bindingTraceContext.getBindingContext(), null);
|
||||
return new Result<AnalyzeExhaust>(analyzeExhaust, PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
}, false);
|
||||
project.putUserData(ANALYZE_EXHAUST, bindingContextCachedValue);
|
||||
}
|
||||
return bindingContextCachedValue.getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +53,10 @@ import org.jetbrains.jet.plugin.actions.JetAddImportAction;
|
||||
import org.jetbrains.jet.plugin.caches.JetCacheManager;
|
||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Check possibility and perform fix for unresolved references.
|
||||
@@ -85,7 +88,7 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
assert referenceName != null;
|
||||
|
||||
List<FqName> result = Lists.newArrayList();
|
||||
result.addAll(getClassNames(referenceName, file.getProject()));
|
||||
result.addAll(getClassNames(referenceName, (JetFile) file));
|
||||
result.addAll(getJetTopLevelFunctions(referenceName, element, file.getProject()));
|
||||
result.addAll(getJetExtensionFunctions(referenceName, element, file.getProject()));
|
||||
|
||||
@@ -142,11 +145,11 @@ public class ImportClassAndFunFix extends JetHintAction<JetSimpleNameExpression>
|
||||
/*
|
||||
* Searches for possible class names in kotlin context and java facade.
|
||||
*/
|
||||
public static Collection<FqName> getClassNames(@NotNull String referenceName, @NotNull Project project) {
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
public static Collection<FqName> getClassNames(@NotNull String referenceName, @NotNull JetFile file) {
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(file.getProject());
|
||||
Set<FqName> possibleResolveNames = Sets.newHashSet();
|
||||
possibleResolveNames.addAll(JetCacheManager.getInstance(project).getNamesCache().getFQNamesByName(referenceName, scope));
|
||||
possibleResolveNames.addAll(getJavaClasses(referenceName, project, scope));
|
||||
possibleResolveNames.addAll(JetCacheManager.getInstance(file.getProject()).getNamesCache().getFQNamesByName(referenceName, file, scope));
|
||||
possibleResolveNames.addAll(getJavaClasses(referenceName, file.getProject(), scope));
|
||||
|
||||
// TODO: Do appropriate sorting
|
||||
return Lists.newArrayList(possibleResolveNames);
|
||||
|
||||
@@ -16,18 +16,19 @@
|
||||
|
||||
package org.jetbrains.jet.plugin.refactoring.rename;
|
||||
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.refactoring.MultiFileTestCase;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.FqName;
|
||||
@@ -64,9 +65,23 @@ public class RenameInKotlinTest extends MultiFileTestCase {
|
||||
doTest(new PerformAction() {
|
||||
@Override
|
||||
public void performAction(VirtualFile rootDir, VirtualFile rootAfter) throws Exception {
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCache(
|
||||
getProject(), GlobalSearchScope.allScope(getProject()))
|
||||
.getBindingContext();
|
||||
VirtualFile child = rootDir.findChild(getTestName(false) + ".kt");
|
||||
if (child == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
Document document = FileDocumentManager.getInstance().getDocument(child);
|
||||
if (document == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PsiFile file = PsiDocumentManager.getInstance(getProject()).getPsiFile(document);
|
||||
if (!(file instanceof JetFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile((JetFile)file)
|
||||
.getBindingContext();
|
||||
ClassDescriptor classDescriptor = bindingContext.get(BindingContext.FQNAME_TO_CLASS_DESCRIPTOR, qClassName);
|
||||
|
||||
assertNotNull(classDescriptor);
|
||||
@@ -79,8 +94,6 @@ public class RenameInKotlinTest extends MultiFileTestCase {
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
VirtualFileManager.getInstance().refresh(false);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user