diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/referenceUtil.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/referenceUtil.kt index 6b076a2a7c1..e7ab774c47d 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/referenceUtil.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/references/referenceUtil.kt @@ -24,8 +24,6 @@ import org.jetbrains.kotlin.idea.util.ProjectRootsUtil import org.jetbrains.kotlin.kdoc.psi.impl.KDocName import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType -import org.jetbrains.kotlin.psi.psiUtil.getQualifiedElementSelector -import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.emptyOrSingletonList @@ -90,15 +88,14 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean { } if ((parent as? PsiNewExpression)?.resolveConstructor()?.unwrapped == unwrappedCandidate) return true } - if (this is PsiReferenceExpression && candidateTarget is JetObjectDeclaration && unwrappedTargets.size() == 1) { + if (this is PsiJavaCodeReferenceElement && candidateTarget is JetObjectDeclaration && unwrappedTargets.size() == 1) { val referredClass = unwrappedTargets.first() if (referredClass is JetClass && candidateTarget in referredClass.getCompanionObjects()) { - val parentReference = getParent().getReference() - if (parentReference != null) { - return parentReference.unwrappedTargets.any { - (it is JetProperty || it is JetNamedFunction) && it.getParent()?.getParent() == candidateTarget - } - } + if (getParent() is PsiImportStaticStatement) return true + + return getParent().getReference()?.unwrappedTargets?.any { + (it is JetProperty || it is JetNamedFunction) && it.getParent()?.getParent() == candidateTarget + } ?: false } } return false diff --git a/idea/testData/findUsages/kotlin/companionObject/javaUsage.1.java b/idea/testData/findUsages/kotlin/companionObject/javaUsage.1.java index 1c61e93221c..8ccc8f3d8b8 100644 --- a/idea/testData/findUsages/kotlin/companionObject/javaUsage.1.java +++ b/idea/testData/findUsages/kotlin/companionObject/javaUsage.1.java @@ -1,3 +1,5 @@ +import static Foo.*; + class JavaUsage { public static void main(String[] args) { System.out.println(Foo.CONST); diff --git a/idea/testData/findUsages/kotlin/companionObject/javaUsage.results.txt b/idea/testData/findUsages/kotlin/companionObject/javaUsage.results.txt index daca4ec2ea8..21d9d17836d 100644 --- a/idea/testData/findUsages/kotlin/companionObject/javaUsage.results.txt +++ b/idea/testData/findUsages/kotlin/companionObject/javaUsage.results.txt @@ -1,3 +1,4 @@ -Class static member access (3: 28) System.out.println(Foo.CONST); -Class static member access (4: 9) Foo.s(); -Unclassified usage (5: 13) Foo.Companion.f(); \ No newline at end of file +Class static member access (5: 28) System.out.println(Foo.CONST); +Class static member access (6: 9) Foo.s(); +Unclassified usage (1: 15) import static Foo.*; +Unclassified usage (7: 13) Foo.Companion.f(); \ No newline at end of file diff --git a/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.java b/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.java new file mode 100644 index 00000000000..6787bf641da --- /dev/null +++ b/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.java @@ -0,0 +1,8 @@ +import static companionObjectWithStatics.Foo.* + +class JavaUsage { + public static void main(String[] args) { + System.out.println(CONST + CONST); + foo() + } +} \ No newline at end of file diff --git a/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.kt b/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.kt new file mode 100644 index 00000000000..6aafba50900 --- /dev/null +++ b/idea/testData/inspections/unusedSymbol/object/companionObjectWithStatics.kt @@ -0,0 +1,10 @@ +package companionObjectWithStatics + +class Foo { + companion object { + platformStatic fun foo() { + } + + val CONST = 111 + } +} \ No newline at end of file