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