Change Signature: Use lazy analysis
This commit is contained in:
+14
-7
@@ -71,8 +71,10 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
((JetDelegatorToSuperCall) call).getCalleeExpression().getConstructorReferenceExpression();
|
||||
|
||||
if (receiverExpr instanceof JetSimpleNameExpression) {
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
JetElement jetElement = PsiTreeUtil.getParentOfType(element, JetElement.class);
|
||||
if (jetElement == null) return null;
|
||||
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(jetElement);
|
||||
DeclarationDescriptor descriptor =
|
||||
bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) receiverExpr);
|
||||
|
||||
@@ -85,13 +87,12 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
}
|
||||
|
||||
public static void invokeChangeSignature(
|
||||
@NotNull PsiElement element,
|
||||
@NotNull JetElement element,
|
||||
@NotNull PsiElement context,
|
||||
@NotNull Project project,
|
||||
@Nullable Editor editor
|
||||
) {
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(element);
|
||||
FunctionDescriptor functionDescriptor = findDescriptor(element, project, editor, bindingContext);
|
||||
if (functionDescriptor == null) {
|
||||
return;
|
||||
@@ -142,7 +143,9 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
|
||||
PsiElement elementAtCaret = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
if (element != null && elementAtCaret != null) {
|
||||
invokeChangeSignature(element, elementAtCaret, project, editor);
|
||||
assert element instanceof JetElement : "This handler must be invoked for elements of JetLanguage : " + element.getText();
|
||||
|
||||
invokeChangeSignature((JetElement) element, elementAtCaret, project, editor);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +153,11 @@ public class JetChangeSignatureHandler implements ChangeSignatureHandler {
|
||||
public void invoke(@NotNull Project project, @NotNull PsiElement[] elements, @Nullable DataContext dataContext) {
|
||||
if (elements.length != 1) return;
|
||||
Editor editor = dataContext != null ? PlatformDataKeys.EDITOR.getData(dataContext) : null;
|
||||
invokeChangeSignature(elements[0], elements[0], project, editor);
|
||||
|
||||
PsiElement element = elements[0];
|
||||
assert element instanceof JetElement : "This handler must be invoked for elements of JetLanguage : " + element.getText();
|
||||
|
||||
invokeChangeSignature((JetElement) element, element, project, editor);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
+1
-1
@@ -131,7 +131,7 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
|
||||
JetChangeInfo changeInfo = (JetChangeInfo) info;
|
||||
PsiElement function = info.getMethod();
|
||||
PsiElement element = function != null ? function : changeInfo.getContext();
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile)element.getContainingFile()).getBindingContext();
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement((JetElement) element);
|
||||
FunctionDescriptor oldDescriptor = changeInfo.getOldDescriptor();
|
||||
JetScope parametersScope = null;
|
||||
DeclarationDescriptor containingDeclaration = oldDescriptor != null ? oldDescriptor.getContainingDeclaration() : null;
|
||||
|
||||
@@ -80,7 +80,8 @@ public class JetParameterInfo implements ParameterInfo {
|
||||
if (!(inheritedFunction instanceof JetFunction))
|
||||
return name;
|
||||
|
||||
List<JetParameter> inheritedParameters = ((JetFunction) inheritedFunction).getValueParameters();
|
||||
JetFunction inheritedJetFunction = (JetFunction) inheritedFunction;
|
||||
List<JetParameter> inheritedParameters = inheritedJetFunction.getValueParameters();
|
||||
|
||||
if (!isInherited || oldIndex < 0 || oldIndex >= baseFunction.getParametersCount() || oldIndex >= inheritedParameters.size())
|
||||
return name;
|
||||
@@ -90,8 +91,8 @@ public class JetParameterInfo implements ParameterInfo {
|
||||
String inheritedParamName = inheritedParam.getName();
|
||||
|
||||
if (oldParam.getName().equals(inheritedParamName)) {
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) inheritedFunction.getContainingFile()).getBindingContext();
|
||||
JetScope parametersScope = JetChangeSignatureUsageProcessor.getFunctionBodyScope((JetFunction) inheritedFunction, bindingContext);
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(inheritedJetFunction);
|
||||
JetScope parametersScope = JetChangeSignatureUsageProcessor.getFunctionBodyScope(inheritedJetFunction, bindingContext);
|
||||
|
||||
if (parametersScope != null && parametersScope.getLocalVariable(Name.identifier(name)) == null)
|
||||
return name;
|
||||
|
||||
+7
-6
@@ -28,7 +28,7 @@ import com.intellij.refactoring.util.CommonRefactoringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.Visibilities;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
@@ -198,7 +198,7 @@ public class JetChangeSignatureTest extends CodeInsightTestCase {
|
||||
private void doTestUnmodifiableCheck() throws Exception {
|
||||
try {
|
||||
JetChangeInfo changeInfo = getChangeInfo();
|
||||
PsiFile containingFile = changeInfo.getMethod().getContainingFile();
|
||||
JetElement method = (JetElement) changeInfo.getMethod();
|
||||
JetChangeSignatureConfiguration empty = new JetChangeSignatureConfiguration() {
|
||||
@Override
|
||||
public void configure(
|
||||
@@ -211,9 +211,10 @@ public class JetChangeSignatureTest extends CodeInsightTestCase {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
BindingContext context = AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) containingFile).getBindingContext();
|
||||
BindingContext context = AnalyzerFacadeWithCache.getContextForElement(method);
|
||||
|
||||
ChangeSignaturePackage
|
||||
.runChangeSignature(getProject(), changeInfo.getOldDescriptor(), empty, context, changeInfo.getMethod(), "test");
|
||||
.runChangeSignature(getProject(), changeInfo.getOldDescriptor(), empty, context, method, "test");
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
assertTrue(e.getMessage().startsWith("Refactoring cannot be"));
|
||||
@@ -260,11 +261,11 @@ public class JetChangeSignatureTest extends CodeInsightTestCase {
|
||||
configureByFile(getTestName(false) + "Before.kt");
|
||||
Editor editor = getEditor();
|
||||
PsiFile file = getFile();
|
||||
PsiElement element = new JetChangeSignatureHandler().findTargetMember(file, editor);
|
||||
JetElement element = (JetElement) new JetChangeSignatureHandler().findTargetMember(file, editor);
|
||||
assertNotNull("Target element is null", element);
|
||||
Project project = getProject();
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacadeWithCache.analyzeFileWithCache((JetFile) element.getContainingFile()).getBindingContext();
|
||||
AnalyzerFacadeWithCache.getContextForElement(element);
|
||||
PsiElement context = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
assertNotNull(context);
|
||||
FunctionDescriptor functionDescriptor = JetChangeSignatureHandler.findDescriptor(element, project, editor, bindingContext);
|
||||
|
||||
Reference in New Issue
Block a user