Change Signature: Process Kotlin-side calls of Java methods overriding Kotlin declarations

This commit is contained in:
Alexey Sedunov
2015-04-14 14:53:10 +03:00
parent 58bee8c57f
commit 6e2076d602
3 changed files with 34 additions and 0 deletions
@@ -21,6 +21,8 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Ref;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.search.SearchScope;
import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.refactoring.changeSignature.ChangeInfo;
@@ -43,6 +45,7 @@ import kotlin.Unit;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.idea.JetFileType;
import org.jetbrains.kotlin.idea.caches.resolve.ResolvePackage;
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde;
import org.jetbrains.kotlin.idea.codeInsight.JetFileReferencesResolver;
@@ -93,6 +96,23 @@ public class JetChangeSignatureUsageProcessor implements ChangeSignatureUsagePro
}
else {
result.add(functionUsageInfo);
PsiElement callee = functionUsageInfo.getElement();
if (callee == null) continue;
SearchScope scope = callee.getUseScope();
if (scope instanceof GlobalSearchScope) {
scope = GlobalSearchScope.getScopeRestrictedByFileTypes((GlobalSearchScope) scope, JetFileType.INSTANCE);
}
for (PsiReference reference : ReferencesSearch.search(callee, scope)) {
PsiElement element = reference.getElement();
JetCallElement callElement = PsiTreeUtil.getParentOfType(element, JetCallElement.class);
JetExpression calleeExpression = callElement != null ? callElement.getCalleeExpression() : null;
if (calleeExpression != null && PsiTreeUtil.isAncestor(calleeExpression, element, false)) {
result.add(new JetFunctionCallUsage(callElement, changeInfo.getMethodDescriptor().getOriginalPrimaryFunction()));
}
}
}
}
}
@@ -4,4 +4,11 @@ open class A {
class B: A() {
override fun foo(n: Int, s: String, o: Any?): String = ""
}
fun test() {
A().foo(1, "abc", "def")
B().foo(2, "abc", "def")
X().foo(3, "abc", "def")
Y().foo(4, "abc", "def")
}
@@ -4,4 +4,11 @@ open class A {
class B: A() {
override fun foo(n: Int): String = ""
}
fun test() {
A().foo(1)
B().foo(2)
X().foo(3)
Y().foo(4)
}