From 5e34791e685168ee680befed130b8111c9f9045c Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 30 Apr 2014 19:53:24 +0400 Subject: [PATCH] Smart completion should not suggest variants for private signatures #KT-4899 Fixed --- .../jet/plugin/completion/ExpectedInfos.kt | 7 ++++++- .../completion/smart/NoPrivateOverload.kt | 15 +++++++++++++++ .../JvmSmartCompletionTestGenerated.java | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 idea/testData/completion/smart/NoPrivateOverload.kt diff --git a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt index c12bbe225f6..3f54fe3dbb4 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/ExpectedInfos.kt @@ -49,6 +49,8 @@ import org.jetbrains.jet.plugin.completion.smart.isSubtypeOf import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall import org.jetbrains.jet.lang.resolve.calls.util.noErrorsInValueArguments import org.jetbrains.jet.lang.resolve.calls.util.hasUnmappedParameters +import org.jetbrains.jet.lang.descriptors.Visibilities +import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility enum class Tail { COMMA @@ -131,7 +133,10 @@ class ExpectedInfos(val bindingContext: BindingContext, val moduleDescriptor: Mo for (candidate: ResolvedCall in results.getAllCandidates()!!) { // consider only candidates with more arguments than in the truncated call and with all arguments before the current one matched if (candidate.noErrorsInValueArguments() && (isFunctionLiteralArgument || candidate.hasUnmappedParameters())) { - val parameters = candidate.getResultingDescriptor().getValueParameters() + val descriptor = candidate.getResultingDescriptor() + if (!Visibilities.isVisible(descriptor, resolutionScope.getContainingDeclaration())) continue + + val parameters = descriptor.getValueParameters() if (isFunctionLiteralArgument) { if (argumentIndex != parameters.size - 1) continue } diff --git a/idea/testData/completion/smart/NoPrivateOverload.kt b/idea/testData/completion/smart/NoPrivateOverload.kt new file mode 100644 index 00000000000..398eac2cf5b --- /dev/null +++ b/idea/testData/completion/smart/NoPrivateOverload.kt @@ -0,0 +1,15 @@ +fun f(p1: Any, p2: String, p3: Int) { + C().foo() +} + +class C { + public fun foo(p1: String, p2: Any) { + } + + private fun foo(p1: Int) { + } +} + +// ABSENT: p1 +// EXIST: p2 +// ABSENT: p3 diff --git a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java index cfb278de290..7019469b2c5 100644 --- a/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java +++ b/idea/tests/org/jetbrains/jet/completion/JvmSmartCompletionTestGenerated.java @@ -301,6 +301,11 @@ public class JvmSmartCompletionTestGenerated extends AbstractJvmSmartCompletionT doTest("idea/testData/completion/smart/NoNothing.kt"); } + @TestMetadata("NoPrivateOverload.kt") + public void testNoPrivateOverload() throws Exception { + doTest("idea/testData/completion/smart/NoPrivateOverload.kt"); + } + @TestMetadata("NoSillyAssignment.kt") public void testNoSillyAssignment() throws Exception { doTest("idea/testData/completion/smart/NoSillyAssignment.kt");