Don't report unused symbol if secondary constructor used
#KT-6997 Fixed
This commit is contained in:
committed by
Alexey Sedunov
parent
c6290efbe2
commit
d1308ebf84
@@ -50,7 +50,7 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
|
||||
|
||||
if (this is JetReference) {
|
||||
return targets.any {
|
||||
it is PsiMethod && it.isConstructor() && it.getContainingClass() == unwrappedCandidate
|
||||
it.isConstructorOf(unwrappedCandidate)
|
||||
|| it is JetObjectDeclaration && it.isCompanion() && it.getNonStrictParentOfType<JetClass>() == unwrappedCandidate
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,12 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
private fun PsiElement.isConstructorOf(unwrappedCandidate: PsiElement) =
|
||||
// call to Java constructor
|
||||
(this is PsiMethod && isConstructor() && getContainingClass() == unwrappedCandidate) ||
|
||||
// call to Kotlin constructor
|
||||
(this is JetSecondaryConstructor && getStrictParentOfType<JetClass>() == unwrappedCandidate)
|
||||
|
||||
fun AbstractJetReference<out JetExpression>.renameImplicitConventionalCall(newName: String?): JetExpression {
|
||||
if (newName == null) return expression
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetClass
|
||||
// OPTIONS: usages, constructorUsages
|
||||
open class <caret>A {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
class B {
|
||||
public static void foo() {
|
||||
new A()
|
||||
}
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
New instance creation (3: 13) new A()
|
||||
@@ -0,0 +1,5 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetClass
|
||||
// OPTIONS: usages, constructorUsages
|
||||
open class <caret>A {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fun foo() {
|
||||
A()
|
||||
}
|
||||
+1
@@ -0,0 +1 @@
|
||||
New instance creation (2: 5) A()
|
||||
@@ -0,0 +1,7 @@
|
||||
fun main(args: Array<String>) {
|
||||
A()
|
||||
}
|
||||
|
||||
class A {
|
||||
constructor() {}
|
||||
}
|
||||
@@ -257,6 +257,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaClassSecondaryCtrUsages.0.kt")
|
||||
public void testJavaClassSecondaryCtrUsages() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/javaClassSecondaryCtrUsages.0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("javaDerivedClassUsages1.0.kt")
|
||||
public void testJavaDerivedClassUsages1() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/javaDerivedClassUsages1.0.kt");
|
||||
@@ -395,6 +401,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinClassSecondaryCtorUsages.0.kt")
|
||||
public void testKotlinClassSecondaryCtorUsages() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/kotlinClassSecondaryCtorUsages.0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kotlinDeeplyNestedClassAllUsages.0.kt")
|
||||
public void testKotlinDeeplyNestedClassAllUsages() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findClassUsages/kotlinDeeplyNestedClassAllUsages.0.kt");
|
||||
|
||||
Reference in New Issue
Block a user