KT-6877 Wrong unused function inspection on anonymous object member
#KT-6877 fixed
This commit is contained in:
@@ -805,9 +805,12 @@ public class JetPsiUtil {
|
||||
return ((JetClassInitializer) current).getBody();
|
||||
}
|
||||
if (current instanceof JetProperty || current instanceof JetFunction) {
|
||||
if (parent instanceof JetFile || (parent instanceof JetClassBody && !isMemberOfObjectExpression((JetCallableDeclaration) current))) {
|
||||
if (parent instanceof JetFile) {
|
||||
return (JetElement) current;
|
||||
}
|
||||
else if (parent instanceof JetClassBody && !isMemberOfObjectExpression((JetCallableDeclaration) current)) {
|
||||
return (JetElement) parent;
|
||||
}
|
||||
}
|
||||
if (current instanceof JetBlockExpression || current instanceof JetParameter) {
|
||||
return (JetElement) current;
|
||||
|
||||
+12
@@ -0,0 +1,12 @@
|
||||
// PSI_ELEMENT: org.jetbrains.kotlin.psi.JetNamedFunction
|
||||
// OPTIONS: usages
|
||||
class Foo {
|
||||
private val localObject = object : Any() {
|
||||
fun <caret>f() {
|
||||
}
|
||||
}
|
||||
|
||||
fun bar() {
|
||||
localObject.f()
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
Function call (10: 21) localObject.f()
|
||||
@@ -0,0 +1,43 @@
|
||||
class Klass {
|
||||
private val localObject = object {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
val p = 5
|
||||
}
|
||||
|
||||
init {
|
||||
localObject.f()
|
||||
localObject.p
|
||||
}
|
||||
|
||||
|
||||
private fun localObject2() = object {
|
||||
fun f() {
|
||||
}
|
||||
|
||||
val p = 5
|
||||
}
|
||||
|
||||
init {
|
||||
localObject2().f()
|
||||
localObject2().p
|
||||
}
|
||||
|
||||
|
||||
private val a = object {
|
||||
val b = object {
|
||||
val c = object {
|
||||
val d = 5
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
a.b.c.d
|
||||
}
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
Klass()
|
||||
}
|
||||
@@ -648,6 +648,12 @@ public class JetFindUsagesTestGenerated extends AbstractJetFindUsagesTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectExpressionMemberInClass.0.kt")
|
||||
public void testObjectExpressionMemberInClass() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/objectExpressionMemberInClass.0.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("synthesizedFunction.0.kt")
|
||||
public void testSynthesizedFunction() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/findUsages/kotlin/findFunctionUsages/synthesizedFunction.0.kt");
|
||||
|
||||
Reference in New Issue
Block a user