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>?")
|
"fun checkSuperMethods(declaration: JetDeclaration, ignore: Collection<PsiElement>?, actionStringKey: String): MutableList<out PsiElement>?")
|
||||||
@Nullable
|
@Nullable
|
||||||
public static List<? extends PsiElement> checkSuperMethods(
|
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 declarationDescriptor =
|
||||||
(CallableDescriptor)bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
(CallableDescriptor)bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, declaration);
|
||||||
@@ -133,20 +135,14 @@ public class JetRefactoringUtil {
|
|||||||
return Collections.singletonList(declaration);
|
return Collections.singletonList(declaration);
|
||||||
}
|
}
|
||||||
|
|
||||||
final Project project = declaration.getProject();
|
Project project = declaration.getProject();
|
||||||
Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor = ContainerUtil.map2Map(
|
Map<PsiElement, CallableDescriptor> overriddenElementsToDescriptor = new HashMap<PsiElement, CallableDescriptor>();
|
||||||
OverrideResolver.getAllOverriddenDescriptors(declarationDescriptor),
|
for (CallableDescriptor overridenDescriptor : OverrideResolver.getAllOverriddenDescriptors(declarationDescriptor)) {
|
||||||
new Function<CallableDescriptor, Pair<PsiElement, CallableDescriptor>>() {
|
PsiElement overridenDeclaration = DescriptorToDeclarationUtil.getDeclaration(project, overridenDescriptor);
|
||||||
@Override
|
if (overridenDeclaration != null) {
|
||||||
public Pair<PsiElement, CallableDescriptor> fun(CallableDescriptor descriptor) {
|
overriddenElementsToDescriptor.put(overridenDeclaration, overridenDescriptor);
|
||||||
return new Pair<PsiElement, CallableDescriptor>(
|
}
|
||||||
DescriptorToDeclarationUtil.getDeclaration(project, descriptor),
|
}
|
||||||
descriptor
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
overriddenElementsToDescriptor.remove(null);
|
|
||||||
if (ignore != null) {
|
if (ignore != null) {
|
||||||
overriddenElementsToDescriptor.keySet().removeAll(ignore);
|
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");
|
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")
|
@TestMetadata("usagesOfBaseForFunction.0.kt")
|
||||||
public void testUsagesOfBaseForFunction() throws Exception {
|
public void testUsagesOfBaseForFunction() throws Exception {
|
||||||
doTest("idea/testData/findUsages/kotlin/findFunctionUsages/usagesOfBaseForFunction.0.kt");
|
doTest("idea/testData/findUsages/kotlin/findFunctionUsages/usagesOfBaseForFunction.0.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user