KT-7231 Support Parameter Info inside this or super constructor calls

#KT-7231 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-10-07 14:42:46 +03:00
parent 4256fb9c6e
commit 6ed7ac5285
5 changed files with 52 additions and 1 deletions
@@ -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();
@@ -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
}
@@ -0,0 +1,9 @@
class B private constructor(p: Int) {
constructor() : this(<caret>)
protected constructor(s: String) : this()
}
/*
Text: (<highlight>p: Int</highlight>), Disabled: false, Strikeout: false, Green: false
Text: (<highlight>s: String</highlight>), Disabled: false, Strikeout: false, Green: false
*/
@@ -0,0 +1,13 @@
open class A(x: Int) {
protected constructor() : this(1) {}
private constructor(p: String) : this(2) {}
}
class B : A {
constructor() : super(<caret>)
}
/*
Text: (<highlight>x: Int</highlight>), Disabled: false, Strikeout: false, Green: false
Text: (<no parameters>), Disabled: false, Strikeout: false, Green: true
*/
@@ -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");