Introduce cancelable wrapping for resolve cache
This commit is contained in:
@@ -40,7 +40,6 @@ import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.QualifiedExpressionResolver;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
@@ -49,6 +48,7 @@ import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils;
|
||||
import org.jetbrains.jet.plugin.caches.resolve.IDELightClassGenerationSupport;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.stubindex.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -177,10 +177,10 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
public Collection<ClassDescriptor> getTopLevelObjectsByName(
|
||||
@NotNull String name,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull GlobalSearchScope scope
|
||||
) {
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
|
||||
BindingContext context = resolveSession.resolveToElement(expression);
|
||||
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||
|
||||
if (jetScope == null) {
|
||||
@@ -212,7 +212,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
public Collection<FunctionDescriptor> getTopLevelFunctionDescriptorsByName(
|
||||
@NotNull String name,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull GlobalSearchScope scope
|
||||
) {
|
||||
// name parameter can differ from expression.getReferenceName() when expression contains completion suffix
|
||||
@@ -221,7 +221,7 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
|
||||
BindingContext context = resolveSession.resolveToElement(expression);
|
||||
JetScope jetScope = context.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||
|
||||
if (jetScope == null) {
|
||||
@@ -297,12 +297,12 @@ public class JetShortNamesCache extends PsiShortNamesCache {
|
||||
public Collection<DeclarationDescriptor> getJetCallableExtensions(
|
||||
@NotNull Condition<String> acceptedNameCondition,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull GlobalSearchScope searchScope
|
||||
) {
|
||||
Collection<DeclarationDescriptor> resultDescriptors = new ArrayList<DeclarationDescriptor>();
|
||||
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, expression);
|
||||
BindingContext context = resolveSession.resolveToElement(expression);
|
||||
JetExpression receiverExpression = expression.getReceiverExpression();
|
||||
|
||||
if (receiverExpression != null) {
|
||||
|
||||
@@ -32,13 +32,12 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.completion.weigher.JetCompletionSorting;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||
|
||||
@@ -60,8 +59,8 @@ public class CompletionSession {
|
||||
this.parameters = parameters;
|
||||
this.jetReference = jetReference;
|
||||
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) position.getContainingFile());
|
||||
BindingContext expressionBindingContext = ResolveSessionUtils.resolveToElement(resolveSession, jetReference.getExpression());
|
||||
CancelableResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveResultForFile((JetFile) position.getContainingFile());
|
||||
BindingContext expressionBindingContext = resolveSession.resolveToElement(jetReference.getExpression());
|
||||
JetScope scope = expressionBindingContext.get(BindingContext.RESOLUTION_SCOPE, jetReference.getExpression());
|
||||
|
||||
inDescriptor = scope != null ? scope.getContainingDeclaration() : null;
|
||||
@@ -264,7 +263,7 @@ public class CompletionSession {
|
||||
return jetResult.getBindingContext();
|
||||
}
|
||||
|
||||
private ResolveSession getResolveSession() {
|
||||
private CancelableResolveSession getResolveSession() {
|
||||
return jetResult.getResolveSession();
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,10 @@ import com.intellij.openapi.util.Conditions;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
|
||||
public class JetCompletionResultSet {
|
||||
private final ResolveSession resolveSession;
|
||||
private final CancelableResolveSession resolveSession;
|
||||
private final BindingContext bindingContext;
|
||||
private final Condition<DeclarationDescriptor> descriptorFilter;
|
||||
private final CompletionResultSet result;
|
||||
@@ -34,14 +34,14 @@ public class JetCompletionResultSet {
|
||||
|
||||
public JetCompletionResultSet(
|
||||
@NotNull CompletionResultSet result,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull BindingContext bindingContext) {
|
||||
this(result, resolveSession, bindingContext, Conditions.<DeclarationDescriptor>alwaysTrue());
|
||||
}
|
||||
|
||||
public JetCompletionResultSet(
|
||||
@NotNull CompletionResultSet result,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull Condition<DeclarationDescriptor> descriptorFilter) {
|
||||
this.result = result;
|
||||
@@ -50,7 +50,7 @@ public class JetCompletionResultSet {
|
||||
this.descriptorFilter = descriptorFilter;
|
||||
}
|
||||
|
||||
public ResolveSession getResolveSession() {
|
||||
public CancelableResolveSession getResolveSession() {
|
||||
return resolveSession;
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespaceHeader;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.references.JetSimpleNameReference;
|
||||
|
||||
@@ -70,10 +69,9 @@ public class JetPackagesContributor extends CompletionContributor {
|
||||
int prefixLength = parameters.getOffset() - simpleNameReference.getExpression().getTextOffset();
|
||||
result = result.withPrefixMatcher(new PlainPrefixMatcher(name.substring(0, prefixLength)));
|
||||
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(
|
||||
CancelableResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveResultForFile(
|
||||
(JetFile) simpleNameReference.getExpression().getContainingFile());
|
||||
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(
|
||||
resolveSession, simpleNameReference.getExpression());
|
||||
BindingContext bindingContext = resolveSession.resolveToElement(simpleNameReference.getExpression());
|
||||
|
||||
for (LookupElement variant : DescriptorLookupConverter.collectLookupElements(
|
||||
resolveSession, bindingContext, TipsManager.getPackageReferenceVariants(simpleNameReference.getExpression(), bindingContext))) {
|
||||
|
||||
+9
-10
@@ -37,14 +37,13 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.JetVisibilityChecker;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
@@ -58,7 +57,7 @@ import java.util.List;
|
||||
*/
|
||||
public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWithTabActionSupport<
|
||||
JetValueArgumentList,
|
||||
Pair<? extends FunctionDescriptor, ResolveSession>,
|
||||
Pair<? extends FunctionDescriptor, CancelableResolveSession>,
|
||||
JetValueArgument>
|
||||
{
|
||||
public final static Color GREEN_BACKGROUND = new JBColor(new Color(231, 254, 234), Gray._100);
|
||||
@@ -112,7 +111,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Object[] getParametersForDocumentation(Pair<? extends FunctionDescriptor, ResolveSession> p, ParameterInfoContext context) {
|
||||
public Object[] getParametersForDocumentation(Pair<? extends FunctionDescriptor, CancelableResolveSession> p, ParameterInfoContext context) {
|
||||
return ArrayUtil.EMPTY_OBJECT_ARRAY; //todo: ?
|
||||
}
|
||||
|
||||
@@ -200,7 +199,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUI(Pair<? extends FunctionDescriptor, ResolveSession> itemToShow, ParameterInfoUIContext context) {
|
||||
public void updateUI(Pair<? extends FunctionDescriptor, CancelableResolveSession> itemToShow, ParameterInfoUIContext context) {
|
||||
//todo: when we will have ability to pass Array as vararg, implement such feature here too?
|
||||
if (context == null || context.getParameterOwner() == null || !context.getParameterOwner().isValid()) {
|
||||
context.setUIComponentEnabled(false);
|
||||
@@ -216,7 +215,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
JetValueArgumentList argumentList = (JetValueArgumentList) parameterOwner;
|
||||
|
||||
FunctionDescriptor functionDescriptor = itemToShow.first;
|
||||
ResolveSession resolveSession = itemToShow.second;
|
||||
CancelableResolveSession resolveSession = itemToShow.second;
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
|
||||
List<JetValueArgument> valueArguments = argumentList.getArguments();
|
||||
@@ -239,7 +238,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
PsiElement owner = context.getParameterOwner();
|
||||
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, (JetElement) owner);
|
||||
BindingContext bindingContext = resolveSession.resolveToElement((JetElement) owner);
|
||||
|
||||
for (int i = 0; i < valueParameters.size(); ++i) {
|
||||
if (i != 0) {
|
||||
@@ -382,9 +381,9 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
return null;
|
||||
}
|
||||
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(
|
||||
CancelableResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveResultForFile(
|
||||
(JetFile) callNameExpression.getContainingFile());
|
||||
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, callNameExpression);
|
||||
BindingContext bindingContext = resolveSession.resolveToElement(callNameExpression);
|
||||
|
||||
JetScope scope = bindingContext.get(BindingContext.RESOLUTION_SCOPE, callNameExpression);
|
||||
DeclarationDescriptor placeDescriptor = null;
|
||||
@@ -396,7 +395,7 @@ public class JetFunctionParameterInfoHandler implements ParameterInfoHandlerWith
|
||||
|
||||
Name refName = callNameExpression.getReferencedNameAsName();
|
||||
|
||||
Collection<Pair<? extends DeclarationDescriptor, ResolveSession>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, ResolveSession>>();
|
||||
Collection<Pair<? extends DeclarationDescriptor, CancelableResolveSession>> itemsToShow = new ArrayList<Pair<? extends DeclarationDescriptor, CancelableResolveSession>>();
|
||||
for (DeclarationDescriptor variant : variants) {
|
||||
if (variant instanceof FunctionDescriptor) {
|
||||
FunctionDescriptor functionDescriptor = (FunctionDescriptor) variant;
|
||||
|
||||
@@ -32,7 +32,6 @@ import com.intellij.psi.util.CachedValue;
|
||||
import com.intellij.psi.util.CachedValueProvider;
|
||||
import com.intellij.psi.util.CachedValuesManager;
|
||||
import com.intellij.psi.util.PsiModificationTracker;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.SLRUCache;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -61,12 +60,6 @@ public final class AnalyzerFacadeWithCache {
|
||||
private final static Key<CachedValue<SLRUCache<JetFile, AnalyzeExhaust>>> ANALYZE_EXHAUST_FULL = Key.create("ANALYZE_EXHAUST_FULL");
|
||||
|
||||
private static final Object lock = new Object();
|
||||
public static final Function<JetFile, Collection<JetFile>> SINGLE_DECLARATION_PROVIDER = new Function<JetFile, Collection<JetFile>>() {
|
||||
@Override
|
||||
public Collection<JetFile> fun(JetFile file) {
|
||||
return Collections.singleton(file);
|
||||
}
|
||||
};
|
||||
|
||||
private AnalyzerFacadeWithCache() {
|
||||
}
|
||||
@@ -174,17 +167,38 @@ public final class AnalyzerFacadeWithCache {
|
||||
LOG.error(e);
|
||||
}
|
||||
|
||||
private static final SLRUCache<JetFile, CachedValue<CancelableResolveSession>> RESOLVE_SESSION_CACHE = new SLRUCache<JetFile, CachedValue<CancelableResolveSession>>(2, 4) {
|
||||
@NotNull
|
||||
@Override
|
||||
public CachedValue<CancelableResolveSession> createValue(final JetFile file) {
|
||||
final Project fileProject = file.getProject();
|
||||
return CachedValuesManager.getManager(fileProject).createCachedValue(
|
||||
new CachedValueProvider<CancelableResolveSession>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Result<CancelableResolveSession> compute() {
|
||||
Project project = file.getProject();
|
||||
Collection<JetFile> files =
|
||||
JetFilesProvider.getInstance(project).allInScope(GlobalSearchScope.allScope(project));
|
||||
|
||||
// Given file can differ from the original because it can be a virtual copy with some modifications
|
||||
JetFile originalFile = (JetFile) file.getOriginalFile();
|
||||
files.remove(originalFile);
|
||||
files.add(file);
|
||||
|
||||
ResolveSession resolveSession =
|
||||
AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file).getLazyResolveSession(fileProject, files);
|
||||
return Result.create(new CancelableResolveSession(file, resolveSession), PsiModificationTracker.MODIFICATION_COUNT);
|
||||
}
|
||||
},
|
||||
true);
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession getLazyResolveSession(@NotNull JetFile file) {
|
||||
Project fileProject = file.getProject();
|
||||
|
||||
Collection<JetFile> files = JetFilesProvider.getInstance(fileProject).allInScope(GlobalSearchScope.allScope(fileProject));
|
||||
|
||||
// Given file can differ from the original because it can be a virtual copy with some modifications
|
||||
JetFile originalFile = (JetFile) file.getOriginalFile();
|
||||
files.remove(originalFile);
|
||||
files.add(file);
|
||||
|
||||
return AnalyzerFacadeProvider.getAnalyzerFacadeForFile(file).getLazyResolveSession(fileProject, files);
|
||||
public static CancelableResolveSession getLazyResolveSession(@NotNull JetFile file) {
|
||||
synchronized (RESOLVE_SESSION_CACHE) {
|
||||
return RESOLVE_SESSION_CACHE.get(file).getValue();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,155 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.project;
|
||||
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.ModificationTracker;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
public class CancelableResolveSession implements KotlinCodeAnalyzer, ModificationTracker {
|
||||
private final JetFile file;
|
||||
private final ResolveSession resolveSession;
|
||||
private final AtomicLong canceledTracker = new AtomicLong();
|
||||
|
||||
public CancelableResolveSession(JetFile file, ResolveSession resolveSession) {
|
||||
this.file = file;
|
||||
this.resolveSession = resolveSession;
|
||||
}
|
||||
|
||||
public BindingContext resolveToElement(final JetElement element) {
|
||||
return computableWithProcessingCancel(new Computable<BindingContext>() {
|
||||
@Override
|
||||
public BindingContext compute() {
|
||||
return ResolveSessionUtils.resolveToElement(resolveSession, element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModuleDescriptor getRootModuleDescriptor() {
|
||||
return computableWithProcessingCancel(new Computable<ModuleDescriptor>() {
|
||||
@Override
|
||||
public ModuleDescriptor compute() {
|
||||
return resolveSession.getRootModuleDescriptor();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NamespaceDescriptor getPackageDescriptor(@NotNull final Name shortName) {
|
||||
return computableWithProcessingCancel(new Computable<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public NamespaceDescriptor compute() {
|
||||
return resolveSession.getPackageDescriptor(shortName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public NamespaceDescriptor getPackageDescriptorByFqName(final FqName fqName) {
|
||||
return computableWithProcessingCancel(new Computable<NamespaceDescriptor>() {
|
||||
@Override
|
||||
public NamespaceDescriptor compute() {
|
||||
return resolveSession.getPackageDescriptorByFqName(fqName);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ClassDescriptor getClassDescriptor(@NotNull final JetClassOrObject classOrObject) {
|
||||
return computableWithProcessingCancel(new Computable<ClassDescriptor>() {
|
||||
@Override
|
||||
public ClassDescriptor compute() {
|
||||
return resolveSession.getClassDescriptor(classOrObject);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return computableWithProcessingCancel(new Computable<BindingContext>() {
|
||||
@Override
|
||||
public BindingContext compute() {
|
||||
return resolveSession.getBindingContext();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DeclarationDescriptor resolveToDescriptor(final JetDeclaration declaration) {
|
||||
return computableWithProcessingCancel(new Computable<DeclarationDescriptor>() {
|
||||
@Override
|
||||
public DeclarationDescriptor compute() {
|
||||
return resolveSession.resolveToDescriptor(declaration);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void forceResolveAll() {
|
||||
computableWithProcessingCancel(new Computable<Integer>() {
|
||||
@Override
|
||||
public Integer compute() {
|
||||
resolveSession.forceResolveAll();
|
||||
return 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private <T> T computableWithProcessingCancel(Computable<T> computable) {
|
||||
try {
|
||||
return computable.compute();
|
||||
}
|
||||
catch (ProcessCanceledException canceledException) {
|
||||
canceledTracker.getAndIncrement();
|
||||
throw canceledException;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getModificationCount() {
|
||||
return canceledTracker.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SessionResult: " + file + " " + file.hashCode();
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,6 @@ import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
|
||||
public final class WholeProjectAnalyzerFacade {
|
||||
|
||||
@@ -35,12 +33,12 @@ public final class WholeProjectAnalyzerFacade {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static ResolveSession getLazyResolveSessionForFile(@NotNull JetFile file) {
|
||||
public static CancelableResolveSession getLazyResolveResultForFile(@NotNull JetFile file) {
|
||||
return AnalyzerFacadeWithCache.getLazyResolveSession(file);
|
||||
}
|
||||
|
||||
public static BindingContext getContextForElement(@NotNull JetElement jetElement) {
|
||||
ResolveSession resolveSession = getLazyResolveSessionForFile((JetFile) jetElement.getContainingFile());
|
||||
return ResolveSessionUtils.resolveToElement(resolveSession, jetElement);
|
||||
CancelableResolveSession cancelableResolveSession = getLazyResolveResultForFile((JetFile) jetElement.getContainingFile());
|
||||
return cancelableResolveSession.resolveToElement(jetElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,12 +47,12 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.KotlinCodeAnalyzer;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.actions.JetAddImportAction;
|
||||
import org.jetbrains.jet.plugin.caches.JetShortNamesCache;
|
||||
import org.jetbrains.jet.plugin.framework.KotlinFrameworkDetector;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.util.JetPsiHeuristicsUtil;
|
||||
|
||||
@@ -86,15 +86,16 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) element.getContainingFile());
|
||||
CancelableResolveSession cancelableResolveSession = WholeProjectAnalyzerFacade.getLazyResolveResultForFile(
|
||||
(JetFile) element.getContainingFile());
|
||||
|
||||
List<FqName> result = Lists.newArrayList();
|
||||
if (!isSuppressedTopLevelImportInPosition(element)) {
|
||||
result.addAll(getClassNames(referenceName, (JetFile) file, resolveSession));
|
||||
result.addAll(getJetTopLevelFunctions(referenceName, element, resolveSession, file.getProject()));
|
||||
result.addAll(getClassNames(referenceName, (JetFile) file, cancelableResolveSession));
|
||||
result.addAll(getJetTopLevelFunctions(referenceName, element, cancelableResolveSession, file.getProject()));
|
||||
}
|
||||
|
||||
result.addAll(getJetExtensionFunctions(referenceName, element, resolveSession, file.getProject()));
|
||||
result.addAll(getJetExtensionFunctions(referenceName, element, cancelableResolveSession, file.getProject()));
|
||||
|
||||
return Collections2.filter(result, new Predicate<FqName>() {
|
||||
@Override
|
||||
@@ -112,7 +113,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
||||
private static Collection<FqName> getJetTopLevelFunctions(
|
||||
@NotNull String referenceName,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull Project project
|
||||
) {
|
||||
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
||||
@@ -132,7 +133,7 @@ public class AutoImportFix extends JetHintAction<JetSimpleNameExpression> implem
|
||||
private static Collection<FqName> getJetExtensionFunctions(
|
||||
@NotNull final String referenceName,
|
||||
@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull CancelableResolveSession resolveSession,
|
||||
@NotNull Project project
|
||||
) {
|
||||
JetShortNamesCache namesCache = JetShortNamesCache.getKotlinInstance(project);
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -58,7 +58,7 @@ public class MakeOverriddenMemberOpenFix extends JetIntentionAction<JetDeclarati
|
||||
overriddenMembers.clear();
|
||||
containingDeclarationsNames.clear();
|
||||
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) file);
|
||||
CancelableResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveResultForFile((JetFile) file);
|
||||
DeclarationDescriptor descriptor = resolveSession.resolveToDescriptor(element);
|
||||
if (!(descriptor instanceof CallableMemberDescriptor)) return false;
|
||||
CallableMemberDescriptor callableMemberDescriptor = (CallableMemberDescriptor) descriptor;
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.plugin.refactoring.inline;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
@@ -39,17 +55,20 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
import org.jetbrains.jet.plugin.codeInsight.ReferenceToClassesShortening;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
import org.jetbrains.jet.renderer.DescriptorRenderer;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
@Override
|
||||
@@ -211,8 +230,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
return null;
|
||||
}
|
||||
|
||||
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession((JetFile) initializer.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, initializer);
|
||||
BindingContext context = WholeProjectAnalyzerFacade.getContextForElement(initializer);
|
||||
SimpleFunctionDescriptor fun = context.get(BindingContext.FUNCTION, functionLiteralExpression.getFunctionLiteral());
|
||||
if (fun == null || ErrorUtils.containsErrorType(fun)) {
|
||||
return null;
|
||||
@@ -242,12 +260,12 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
JetFile containingFile = (JetFile) inlinedExpressions.get(0).getContainingFile();
|
||||
List<JetFunctionLiteralExpression> functionsToAddParameters = Lists.newArrayList();
|
||||
|
||||
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession(containingFile);
|
||||
CancelableResolveSession cancelableResolveSession = AnalyzerFacadeWithCache.getLazyResolveSession(containingFile);
|
||||
for (JetExpression inlinedExpression : inlinedExpressions) {
|
||||
JetFunctionLiteralExpression functionLiteralExpression = getFunctionLiteralExpression(inlinedExpression);
|
||||
assert functionLiteralExpression != null : "can't find function literal expression for " + inlinedExpression.getText();
|
||||
|
||||
if (needToAddParameterTypes(functionLiteralExpression, resolveSession)) {
|
||||
if (needToAddParameterTypes(functionLiteralExpression, cancelableResolveSession)) {
|
||||
functionsToAddParameters.add(functionLiteralExpression);
|
||||
}
|
||||
}
|
||||
@@ -281,10 +299,10 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
|
||||
private static boolean needToAddParameterTypes(
|
||||
@NotNull JetFunctionLiteralExpression functionLiteralExpression,
|
||||
@NotNull ResolveSession resolveSession
|
||||
@NotNull CancelableResolveSession cancelableResolveSession
|
||||
) {
|
||||
JetFunctionLiteral functionLiteral = functionLiteralExpression.getFunctionLiteral();
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, functionLiteralExpression);
|
||||
BindingContext context = cancelableResolveSession.resolveToElement(functionLiteralExpression);
|
||||
for (Diagnostic diagnostic : context.getDiagnostics()) {
|
||||
AbstractDiagnosticFactory factory = diagnostic.getFactory();
|
||||
PsiElement element = diagnostic.getPsiElement();
|
||||
@@ -302,12 +320,12 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
JetFile containingFile = (JetFile) inlinedExpressions.get(0).getContainingFile();
|
||||
List<JetCallExpression> callsToAddArguments = Lists.newArrayList();
|
||||
|
||||
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession(containingFile);
|
||||
CancelableResolveSession cancelableResolveSession = AnalyzerFacadeWithCache.getLazyResolveSession(containingFile);
|
||||
for (JetExpression inlinedExpression : inlinedExpressions) {
|
||||
JetCallExpression callExpression = getCallExpression(inlinedExpression);
|
||||
assert callExpression != null : "can't find call expression for " + inlinedExpression.getText();
|
||||
|
||||
if (hasIncompleteTypeInferenceDiagnostic(callExpression, resolveSession) && callExpression.getTypeArgumentList() == null) {
|
||||
if (hasIncompleteTypeInferenceDiagnostic(callExpression, cancelableResolveSession) && callExpression.getTypeArgumentList() == null) {
|
||||
callsToAddArguments.add(callExpression);
|
||||
}
|
||||
}
|
||||
@@ -327,8 +345,7 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
}
|
||||
|
||||
JetExpression callee = callExpression.getCalleeExpression();
|
||||
ResolveSession resolveSession = AnalyzerFacadeWithCache.getLazyResolveSession((JetFile) initializer.getContainingFile());
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, initializer);
|
||||
BindingContext context = WholeProjectAnalyzerFacade.getContextForElement(initializer);
|
||||
ResolvedCall<? extends CallableDescriptor> call = context.get(BindingContext.RESOLVED_CALL, callee);
|
||||
if (call == null) {
|
||||
return null;
|
||||
@@ -350,10 +367,10 @@ public class KotlinInlineValHandler extends InlineActionHandler {
|
||||
|
||||
private static boolean hasIncompleteTypeInferenceDiagnostic(
|
||||
@NotNull JetCallExpression callExpression,
|
||||
@NotNull ResolveSession resolveSession
|
||||
@NotNull CancelableResolveSession cancelableResolveSession
|
||||
) {
|
||||
JetExpression callee = callExpression.getCalleeExpression();
|
||||
BindingContext context = ResolveSessionUtils.resolveToElement(resolveSession, callExpression);
|
||||
BindingContext context = cancelableResolveSession.resolveToElement(callExpression);
|
||||
for (Diagnostic diagnostic : context.getDiagnostics()) {
|
||||
if (diagnostic.getFactory() == Errors.TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER && diagnostic.getPsiElement() == callee) {
|
||||
return true;
|
||||
|
||||
@@ -26,11 +26,10 @@ import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSessionUtils;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||
import org.jetbrains.jet.plugin.completion.DescriptorLookupConverter;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
|
||||
|
||||
public class JetSimpleNameReference extends JetPsiReference {
|
||||
@@ -57,8 +56,9 @@ public class JetSimpleNameReference extends JetPsiReference {
|
||||
@NotNull
|
||||
@Override
|
||||
public Object[] getVariants() {
|
||||
ResolveSession resolveSession = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile((JetFile) getExpression().getContainingFile());
|
||||
BindingContext bindingContext = ResolveSessionUtils.resolveToElement(resolveSession, getExpression());
|
||||
CancelableResolveSession resolveSession =
|
||||
WholeProjectAnalyzerFacade.getLazyResolveResultForFile((JetFile) getExpression().getContainingFile());
|
||||
BindingContext bindingContext = resolveSession.resolveToElement(getExpression());
|
||||
|
||||
return DescriptorLookupConverter.collectLookupElements(
|
||||
resolveSession, bindingContext, TipsManager.getReferenceVariants(myExpression, bindingContext));
|
||||
|
||||
@@ -63,7 +63,7 @@ public class KotlinDirectInheritorsSearcher extends QueryExecutorBase<PsiClass,
|
||||
for (JetClassOrObject candidate : candidates) {
|
||||
if (!(candidate instanceof JetClass)) continue;
|
||||
JetFile containingFile = (JetFile) candidate.getContainingFile();
|
||||
KotlinCodeAnalyzer sessionForFile = WholeProjectAnalyzerFacade.getLazyResolveSessionForFile(containingFile);
|
||||
KotlinCodeAnalyzer sessionForFile = WholeProjectAnalyzerFacade.getLazyResolveResultForFile(containingFile);
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) sessionForFile.resolveToDescriptor(candidate);
|
||||
for (JetType type : classDescriptor.getTypeConstructor().getSupertypes()) {
|
||||
ClassifierDescriptor declarationDescriptor = type.getConstructor().getDeclarationDescriptor();
|
||||
|
||||
@@ -22,9 +22,9 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList;
|
||||
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase;
|
||||
import org.jetbrains.jet.plugin.project.CancelableResolveSession;
|
||||
|
||||
/**
|
||||
* User: Alexander Podkhalyuzin
|
||||
@@ -117,7 +117,7 @@ public class JetFunctionParameterInfoTest extends LightCodeInsightFixtureTestCas
|
||||
|
||||
for (Object item : mockCreateParameterInfoContext.getItemsToShow()) {
|
||||
//noinspection unchecked
|
||||
parameterInfoHandler.updateUI((Pair<? extends FunctionDescriptor, ResolveSession>)item, parameterInfoUIContext);
|
||||
parameterInfoHandler.updateUI((Pair<? extends FunctionDescriptor, CancelableResolveSession>)item, parameterInfoUIContext);
|
||||
}
|
||||
assertEquals(expectedResultText, parameterInfoUIContext.getResultText());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user