Skip to content

Commit

Permalink
Merge pull request #80 from t-kameyama/issue_79
Browse files Browse the repository at this point in the history
Fix false negative for imported extension function calls
  • Loading branch information
oboenikui authored Nov 29, 2022
2 parents bc2c6e2 + 59a280c commit 22fbffd
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.isFunctionType
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToCall
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
Expand Down Expand Up @@ -80,11 +79,11 @@ class FillClassInspection(
}
}

private fun KtValueArgumentList.descriptor(): CallableDescriptor? {
private fun KtValueArgumentList.descriptor(): FunctionDescriptor? {
val calleeExpression = getStrictParentOfType<KtCallElement>()?.calleeExpression ?: return null
val descriptor = calleeExpression.resolveToCall()?.resultingDescriptor
val descriptor = calleeExpression.resolveToCall()?.resultingDescriptor as? FunctionDescriptor ?: return null
if (descriptor is JavaCallableMemberDescriptor) return null
return descriptor.takeIf { it is ClassConstructorDescriptor || it is SimpleFunctionDescriptor }
return descriptor
}

class FillClassFix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,52 @@ class FillClassInspectionTest : BasePlatformTestCase() {
)
}

fun `test extension function`() {
doAvailableTest(
"""
class Foo
fun Foo.foo(x: Int, y: Int) {}
fun test() {
Foo().foo(<caret>)
}
""",
"""
class Foo
fun Foo.foo(x: Int, y: Int) {}
fun test() {
Foo().foo(x = 0, y = 0)
}
""",
"Fill function"
)
}

fun `test imported extension function`() {
doAvailableTest(
"""
import Bar.foo
class Foo
object Bar {
fun Foo.foo(x: Int, y: Int) {}
}
fun test() {
Foo().foo(<caret>)
}
""",
"""
import Bar.foo
class Foo
object Bar {
fun Foo.foo(x: Int, y: Int) {}
}
fun test() {
Foo().foo(x = 0, y = 0)
}
""",
"Fill function"
)
}

fun `test fill class constructor without default values`() {
doAvailableTest(
"""
Expand Down

0 comments on commit 22fbffd

Please sign in to comment.