Use lazy analysis in Safe Delete
This commit is contained in:
@@ -270,12 +270,12 @@ public class JetRefactoringUtil {
|
||||
|
||||
@NotNull
|
||||
public static String formatJavaOrLightMethod(@NotNull PsiMethod method) {
|
||||
if (method instanceof KotlinLightMethod) {
|
||||
JetDeclaration declaration = ((KotlinLightMethod) method).getOrigin();
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) declaration.getContainingFile()).getBindingContext();
|
||||
DeclarationDescriptor descriptor =
|
||||
bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
PsiElement originalDeclaration = AsJavaPackage.getUnwrapped(method);
|
||||
if (originalDeclaration instanceof JetDeclaration) {
|
||||
JetDeclaration jetDeclaration = (JetDeclaration) originalDeclaration;
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(jetDeclaration);
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, jetDeclaration);
|
||||
|
||||
if (descriptor != null) return formatFunctionDescriptor(descriptor);
|
||||
}
|
||||
return formatPsiMethod(method, false, false);
|
||||
@@ -283,10 +283,8 @@ public class JetRefactoringUtil {
|
||||
|
||||
@NotNull
|
||||
public static String formatClass(@NotNull JetClassOrObject classOrObject) {
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) classOrObject.getContainingFile()).getBindingContext();
|
||||
DeclarationDescriptor descriptor =
|
||||
bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(classOrObject);
|
||||
DeclarationDescriptor descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, classOrObject);
|
||||
|
||||
if (descriptor instanceof ClassDescriptor) return formatClassDescriptor(descriptor);
|
||||
return "class " + classOrObject.getName();
|
||||
@@ -418,7 +416,7 @@ public class JetRefactoringUtil {
|
||||
}
|
||||
if (addExpression) {
|
||||
JetExpression expression = (JetExpression)element;
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) expression.getContainingFile()).getBindingContext();
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(expression);
|
||||
JetType expressionType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||
if (expressionType == null || !(expressionType instanceof PackageType) &&
|
||||
!JetTypeChecker.INSTANCE.equalTypes(KotlinBuiltIns.
|
||||
|
||||
+2
-6
@@ -35,10 +35,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction;
|
||||
import org.jetbrains.jet.lang.psi.JetProperty;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.plugin.JetBundle;
|
||||
import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache;
|
||||
@@ -91,8 +88,7 @@ class KotlinOverridingDialog extends DialogWrapper {
|
||||
private static String formatElement(PsiElement element) {
|
||||
element = JetPsiUtil.ascendIfPropertyAccessor(element);
|
||||
if (element instanceof JetNamedFunction || element instanceof JetProperty) {
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
|
||||
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, element);
|
||||
if (declarationDescriptor instanceof CallableMemberDescriptor) {
|
||||
|
||||
+1
-2
@@ -39,8 +39,7 @@ fun JetImportDirective.isSafeToDelete(declaration: JetDeclaration): Boolean {
|
||||
}
|
||||
|
||||
if (importReference != null) {
|
||||
val bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache(declaration.getContainingFile() as JetFile).getBindingContext()
|
||||
val bindingContext = AnalyzerFacadeWithCache.getContextForElement(importReference)
|
||||
val referenceDescriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, importReference)
|
||||
val declarationDescriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration)
|
||||
return referenceDescriptor == declarationDescriptor
|
||||
|
||||
Reference in New Issue
Block a user