From 6ed7ac52857ff035658d6d1f0c6620752dfca8b2 Mon Sep 17 00:00:00 2001 From: Valentin Kipyatkov Date: Wed, 7 Oct 2015 14:42:46 +0300 Subject: [PATCH] KT-7231 Support Parameter Info inside this or super constructor calls #KT-7231 Fixed --- .../kotlin/resolve/calls/CallResolver.java | 11 ++++++++++- .../src/org/jetbrains/kotlin/idea/core/Utils.kt | 8 ++++++++ .../functionCall/OtherConstructorFromSecondary.kt | 9 +++++++++ .../functionCall/SuperConstructorFromSecondary.kt | 13 +++++++++++++ .../parameterInfo/ParameterInfoTestGenerated.java | 12 ++++++++++++ 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 idea/testData/parameterInfo/functionCall/OtherConstructorFromSecondary.kt create mode 100644 idea/testData/parameterInfo/functionCall/SuperConstructorFromSecondary.kt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java index 252fbc2efca..3b084800402 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -296,9 +296,16 @@ public class CallResolver { context, expression.getReferencedNameAsName(), expression, CallableDescriptorCollectors.FUNCTIONS_AND_VARIABLES, CallTransformer.FUNCTION_CALL_TRANSFORMER); } - if (calleeExpression instanceof JetConstructorCalleeExpression) { + else if (calleeExpression instanceof JetConstructorCalleeExpression) { return resolveCallForConstructor(context, (JetConstructorCalleeExpression) calleeExpression); } + else if (calleeExpression instanceof JetConstructorDelegationReferenceExpression) { + JetConstructorDelegationCall delegationCall = (JetConstructorDelegationCall) context.call.getCallElement(); + DeclarationDescriptor container = context.scope.getOwnerDescriptor(); + assert container instanceof ConstructorDescriptor : "Trying to resolve JetConstructorDelegationCall not in constructor. scope.ownerDescriptor = " + container; + return resolveConstructorDelegationCall(context, delegationCall, (JetConstructorDelegationReferenceExpression) calleeExpression, + (ConstructorDescriptor) container); + } else if (calleeExpression == null) { return checkArgumentTypesAndFail(context); } @@ -393,6 +400,8 @@ public class CallResolver { @NotNull JetConstructorDelegationReferenceExpression calleeExpression, @NotNull ConstructorDescriptor calleeConstructor ) { + context.trace.record(BindingContext.LEXICAL_SCOPE, call, context.scope); + ClassDescriptor currentClassDescriptor = calleeConstructor.getContainingDeclaration(); boolean isThisCall = calleeExpression.isThis(); diff --git a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/Utils.kt b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/Utils.kt index 8d9ba76cfc3..981f296138b 100644 --- a/idea/idea-core/src/org/jetbrains/kotlin/idea/core/Utils.kt +++ b/idea/idea-core/src/org/jetbrains/kotlin/idea/core/Utils.kt @@ -143,15 +143,23 @@ public fun Call.resolveCandidates( val results = callResolver.resolveFunctionCall(callResolutionContext) var candidates = results.allCandidates!! + + if (callElement is JetConstructorDelegationCall) { // for "this(...)" delegation call exclude caller from candidates + inDescriptor as ConstructorDescriptor + candidates = candidates.filter { it.resultingDescriptor.original != inDescriptor.original } + } + if (filterOutWrongReceiver) { candidates = candidates.filter { it.status != ResolutionStatus.RECEIVER_TYPE_ERROR && it.status != ResolutionStatus.RECEIVER_PRESENCE_ERROR } } + if (filterOutByVisibility) { candidates = candidates.filter { val thisReceiver = ExpressionTypingUtils.normalizeReceiverValueForVisibility(it.dispatchReceiver, bindingContext) Visibilities.isVisible(thisReceiver, it.resultingDescriptor, inDescriptor) } } + return candidates } diff --git a/idea/testData/parameterInfo/functionCall/OtherConstructorFromSecondary.kt b/idea/testData/parameterInfo/functionCall/OtherConstructorFromSecondary.kt new file mode 100644 index 00000000000..d6fa681177c --- /dev/null +++ b/idea/testData/parameterInfo/functionCall/OtherConstructorFromSecondary.kt @@ -0,0 +1,9 @@ +class B private constructor(p: Int) { + constructor() : this() + protected constructor(s: String) : this() +} + +/* +Text: (p: Int), Disabled: false, Strikeout: false, Green: false +Text: (s: String), Disabled: false, Strikeout: false, Green: false +*/ \ No newline at end of file diff --git a/idea/testData/parameterInfo/functionCall/SuperConstructorFromSecondary.kt b/idea/testData/parameterInfo/functionCall/SuperConstructorFromSecondary.kt new file mode 100644 index 00000000000..2c7dabe0048 --- /dev/null +++ b/idea/testData/parameterInfo/functionCall/SuperConstructorFromSecondary.kt @@ -0,0 +1,13 @@ +open class A(x: Int) { + protected constructor() : this(1) {} + private constructor(p: String) : this(2) {} +} + +class B : A { + constructor() : super() +} + +/* +Text: (x: Int), Disabled: false, Strikeout: false, Green: false +Text: (), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java index 7a70ab51694..47eef14ff3a 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java @@ -184,6 +184,12 @@ public class ParameterInfoTestGenerated extends AbstractParameterInfoTest { doTest(fileName); } + @TestMetadata("OtherConstructorFromSecondary.kt") + public void testOtherConstructorFromSecondary() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/parameterInfo/functionCall/OtherConstructorFromSecondary.kt"); + doTest(fileName); + } + @TestMetadata("Println.kt") public void testPrintln() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/parameterInfo/functionCall/Println.kt"); @@ -256,6 +262,12 @@ public class ParameterInfoTestGenerated extends AbstractParameterInfoTest { doTest(fileName); } + @TestMetadata("SuperConstructorFromSecondary.kt") + public void testSuperConstructorFromSecondary() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/parameterInfo/functionCall/SuperConstructorFromSecondary.kt"); + doTest(fileName); + } + @TestMetadata("TooManyArgs.kt") public void testTooManyArgs() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/parameterInfo/functionCall/TooManyArgs.kt");