Use lazy analysis in live templates
This commit is contained in:
+1
-5
@@ -30,7 +30,6 @@ import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
|||||||
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
import org.jetbrains.jet.lang.descriptors.ClassKind;
|
||||||
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
import org.jetbrains.jet.lang.descriptors.ConstructorDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.JetFile;
|
|
||||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
import org.jetbrains.jet.lang.psi.JetReferenceExpression;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||||
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
|
import org.jetbrains.jet.plugin.codeInsight.ImplementMethodsHandler;
|
||||||
@@ -61,10 +60,7 @@ class AnonymousTemplateEditingListener extends TemplateEditingAdapter {
|
|||||||
PsiElement name = psiFile.findElementAt(variableRange.getStartOffset());
|
PsiElement name = psiFile.findElementAt(variableRange.getStartOffset());
|
||||||
if (name != null && name.getParent() instanceof JetReferenceExpression) {
|
if (name != null && name.getParent() instanceof JetReferenceExpression) {
|
||||||
JetReferenceExpression ref = (JetReferenceExpression) name.getParent();
|
JetReferenceExpression ref = (JetReferenceExpression) name.getParent();
|
||||||
|
DeclarationDescriptor descriptor = AnalyzerFacadeWithCache.getContextForElement(ref).get(BindingContext.REFERENCE_TARGET, ref);
|
||||||
BindingContext bc = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) psiFile)
|
|
||||||
.getBindingContext();
|
|
||||||
DeclarationDescriptor descriptor = bc.get(BindingContext.REFERENCE_TARGET, ref);
|
|
||||||
if (descriptor instanceof ClassDescriptor) {
|
if (descriptor instanceof ClassDescriptor) {
|
||||||
classRef = ref;
|
classRef = ref;
|
||||||
classDescriptor = (ClassDescriptor) descriptor;
|
classDescriptor = (ClassDescriptor) descriptor;
|
||||||
|
|||||||
@@ -29,7 +29,6 @@ import com.intellij.psi.PsiFile;
|
|||||||
import com.intellij.psi.PsiNamedElement;
|
import com.intellij.psi.PsiNamedElement;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.analyzer.AnalyzeExhaust;
|
|
||||||
import org.jetbrains.jet.di.InjectorForMacros;
|
import org.jetbrains.jet.di.InjectorForMacros;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
|
||||||
@@ -40,6 +39,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
|||||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||||
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
import org.jetbrains.jet.plugin.codeInsight.TipsManager;
|
||||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||||
|
import org.jetbrains.jet.plugin.project.ResolveSessionForBodies;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
@@ -60,14 +60,16 @@ public abstract class BaseJetVariableMacro extends Macro {
|
|||||||
JetExpression contextExpression = findContextExpression(psiFile, context.getStartOffset());
|
JetExpression contextExpression = findContextExpression(psiFile, context.getStartOffset());
|
||||||
if (contextExpression == null) return null;
|
if (contextExpression == null) return null;
|
||||||
|
|
||||||
AnalyzeExhaust analyzeExhaust = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) psiFile);
|
ResolveSessionForBodies resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile((JetFile) psiFile);
|
||||||
BindingContext bc = analyzeExhaust.getBindingContext();
|
|
||||||
|
BindingContext bc = resolveSession.resolveToElement(contextExpression);
|
||||||
JetScope scope = bc.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
|
JetScope scope = bc.get(BindingContext.RESOLUTION_SCOPE, contextExpression);
|
||||||
if (scope == null) {
|
if (scope == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
ExpressionTypingServices callResolverContext = new InjectorForMacros(project, analyzeExhaust.getModuleDescriptor()).getExpressionTypingServices();
|
ExpressionTypingServices callResolverContext =
|
||||||
|
new InjectorForMacros(project, resolveSession.getModuleDescriptor()).getExpressionTypingServices();
|
||||||
|
|
||||||
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
List<VariableDescriptor> filteredDescriptors = new ArrayList<VariableDescriptor>();
|
||||||
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
|
for (DeclarationDescriptor declarationDescriptor : scope.getAllDescriptors()) {
|
||||||
|
|||||||
@@ -87,13 +87,12 @@ public class JetAnonymousSuperMacro extends Macro {
|
|||||||
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
|
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(context.getEditor().getDocument());
|
||||||
if (!(psiFile instanceof JetFile)) return null;
|
if (!(psiFile instanceof JetFile)) return null;
|
||||||
|
|
||||||
BindingContext bc = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) psiFile)
|
|
||||||
.getBindingContext();
|
|
||||||
JetExpression expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(context.getStartOffset()), JetExpression.class);
|
JetExpression expression = PsiTreeUtil.getParentOfType(psiFile.findElementAt(context.getStartOffset()), JetExpression.class);
|
||||||
|
if (expression == null) return null;
|
||||||
|
|
||||||
|
BindingContext bc = AnalyzerFacadeWithCache.getContextForElement(expression);
|
||||||
JetScope scope = bc.get(BindingContext.RESOLUTION_SCOPE, expression);
|
JetScope scope = bc.get(BindingContext.RESOLUTION_SCOPE, expression);
|
||||||
if (scope == null) {
|
if (scope == null) return null;
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<PsiNamedElement> result = new ArrayList<PsiNamedElement>();
|
List<PsiNamedElement> result = new ArrayList<PsiNamedElement>();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user