Find Usages: Skip overriden descriptors which have no corresponding declaration (EA-58371)
This commit is contained in:
@@ -122,9 +122,11 @@ public class JetRefactoringUtil {
|
||||
"fun checkSuperMethods(declaration: JetDeclaration, ignore: Collection<PsiElement>?, actionStringKey: String): MutableList<out PsiElement>?")
|
||||
@Nullable
|
||||
public static List<? extends PsiElement> checkSuperMethods(
|
||||
@NotNull JetDeclaration declaration, @Nullable Collection<PsiElement> ignore, @NotNull String actionStringKey
|
||||
@NotNull JetDeclaration declaration,
|
||||
@Nullable Collection<PsiElement> ignore,
|
||||
@NotNull String actionStringKey
|
||||
) {
|
||||
final BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
|
||||
BindingContext bindingContext = AnalyzerFacadeWithCache.getContextForElement(declaration);
|
||||
|
||||
CallableDescriptor declarationDescriptor =
|
||||
(CallableDescriptor)bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||
@@ -133,20 +135,14 @@ public class JetRefactoringUtil {
|
||||
return Collections.singletonList(declaration);
|
||||
}
|
||||
|
||||
final Project project = declaration.getProject();
|
||||
Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor = ContainerUtil.map2Map(
|
||||
OverrideResolver.getAllOverriddenDescriptors(declarationDescriptor),
|
||||
new Function<CallableDescriptor, Pair<PsiElement, CallableDescriptor>>() {
|
||||
@Override
|
||||
public Pair<PsiElement, CallableDescriptor> fun(CallableDescriptor descriptor) {
|
||||
return new Pair<PsiElement, CallableDescriptor>(
|
||||
DescriptorToDeclarationUtil.getDeclaration(project, descriptor),
|
||||
descriptor
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
overriddenElementsToDescriptor.remove(null);
|
||||
Project project = declaration.getProject();
|
||||
Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor = new HashMap<PsiElement, CallableDescriptor>();
|
||||
for (CallableDescriptor overridenDescriptor : OverrideResolver.getAllOverriddenDescriptors(declarationDescriptor)) {
|
||||
PsiElement overridenDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, overridenDescriptor);
|
||||
if (overridenDeclaration != null) {
|
||||
overriddenElementsToDescriptor.put(overridenDeclaration, overridenDescriptor);
|
||||
}
|
||||
}
|
||||
if (ignore != null) {
|
||||
overriddenElementsToDescriptor.keySet().removeAll(ignore);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
// PSI_ELEMENT: org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
// OPTIONS: usages, skipImports
|
||||
|
||||
open data class A(val a: Int)
|
||||
|
||||
class B(b: Int): A(b) {
|
||||
override fun <caret>copy(b: Int): B = B(b)
|
||||
}
|
||||
|
||||
fun main(a: A) {
|
||||
a.copy(1)
|
||||
B(0).copy(1)
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Function call (12: 10) B(0).copy(1)
|
||||
@@ -418,6 +418,11 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
||||
doTest("idea/testData/findUsages/kotlin/findFunctionUsages/kotlinTopLevelMethodUsagesNoImport.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("synthesizedFunction.0.kt")
|
||||
public void testSynthesizedFunction() throws Exception {
|
||||
doTest("idea/testData/findUsages/kotlin/findFunctionUsages/synthesizedFunction.0.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("usagesOfBaseForFunction.0.kt")
|
||||
public void testUsagesOfBaseForFunction() throws Exception {
|
||||
doTest("idea/testData/findUsages/kotlin/findFunctionUsages/usagesOfBaseForFunction.0.kt");
|
||||
|
||||
Reference in New Issue
Block a user