diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetControlFlowProcessor.java index 270d2ebe7f7..a55d09fe88c 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/JetControlFlowProcessor.java @@ -1441,9 +1441,7 @@ public class JetControlFlowProcessor { processParameters(constructor.getValueParameters()); generateCallOrMarkUnresolved(constructor.getDelegationCall()); - if (constructor.getDelegationCall() != null && - constructor.getDelegationCall().getCalleeExpression() != null && - !constructor.getDelegationCall().getCalleeExpression().isThis() + if (constructor.getDelegationCall() != null && !constructor.getDelegationCall().isCallToThis() ) { generateClassOrObjectInitializers(classOrObject); } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 52038e96d3d..2b171a0727b 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -418,7 +418,7 @@ public object PositioningStrategies { public val SECONDARY_CONSTRUCTOR_DELEGATION_CALL: PositioningStrategy = object : PositioningStrategy() { override fun mark(element: JetConstructorDelegationCall): List { - if (element.getCalleeExpression()?.isEmpty() ?: false) { + if (element.isEmpty()) { val constructor = element.getStrictParentOfType()!! return markElement(constructor.getConstructorKeyword()) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationCall.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationCall.java index 6c7e8e19147..8d467d01918 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationCall.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationCall.java @@ -64,4 +64,14 @@ public class JetConstructorDelegationCall extends JetElementImpl implements JetC public JetConstructorDelegationReferenceExpression getCalleeExpression() { return findChildByClass(JetConstructorDelegationReferenceExpression.class); } + + public boolean isEmpty() { + JetConstructorDelegationReferenceExpression callee = getCalleeExpression(); + return callee != null && callee.getFirstChild() == null; + } + + public boolean isCallToThis() { + JetConstructorDelegationReferenceExpression callee = getCalleeExpression(); + return callee != null && callee.isThis(); + } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationReferenceExpression.java b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationReferenceExpression.java index 2d8fe719fac..0822cbd086d 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationReferenceExpression.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/JetConstructorDelegationReferenceExpression.java @@ -28,8 +28,4 @@ public class JetConstructorDelegationReferenceExpression extends JetExpressionIm public boolean isThis() { return findChildByType(JetTokens.THIS_KEYWORD) != null; } - - public boolean isEmpty() { - return getFirstChild() == null; - } } 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 abfa79607c6..21c5092a067 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/CallResolver.java @@ -316,8 +316,7 @@ public class CallResolver { if (call.getCalleeExpression() == null) return checkArgumentTypesAndFail(context); - if (constructorDescriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS && - call.getCalleeExpression().isEmpty()) { + if (constructorDescriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS && call.isEmpty()) { return null; } @@ -376,7 +375,7 @@ public class CallResolver { knownTypeParametersSubstitutor)); } - TracingStrategy tracing = calleeExpression.isEmpty() ? + TracingStrategy tracing = call.isEmpty() ? new TracingStrategyForEmptyConstructorDelegationCall(call, context.call) : TracingStrategyImpl.create(calleeExpression, context.call); diff --git a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetConstructorDelegationCallUsage.kt b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetConstructorDelegationCallUsage.kt index 863a9e48089..419a20c5078 100644 --- a/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetConstructorDelegationCallUsage.kt +++ b/idea/src/org/jetbrains/kotlin/idea/refactoring/changeSignature/usages/JetConstructorDelegationCallUsage.kt @@ -26,11 +26,11 @@ import org.jetbrains.kotlin.psi.JetSecondaryConstructor public class JetConstructorDelegationCallUsage(call: JetConstructorDelegationCall) : JetUsageInfo(call) { override fun processUsage(changeInfo: JetChangeInfo, element: JetConstructorDelegationCall): Boolean { - val isThisCall = element.getCalleeExpression()!!.isThis() + val isThisCall = element.isCallToThis() val psiFactory = JetPsiFactory(element) var elementToWorkWith = element - if (changeInfo.getNewParametersCount() > 0 && element.getCalleeExpression()!!.isEmpty()) { + if (changeInfo.getNewParametersCount() > 0 && element.isEmpty()) { val delegationKindName = if (isThisCall) "this" else "super" elementToWorkWith = element.replace(psiFactory.createConstructorDelegationCall("$delegationKindName()")) as JetConstructorDelegationCall @@ -40,7 +40,7 @@ public class JetConstructorDelegationCallUsage(call: JetConstructorDelegationCal val result = JetFunctionCallUsage( elementToWorkWith, changeInfo.methodDescriptor.originalPrimaryFunction).processUsage(changeInfo, elementToWorkWith) - if (changeInfo.getNewParametersCount() == 0 && !isThisCall && !elementToWorkWith.getCalleeExpression()!!.isEmpty()) { + if (changeInfo.getNewParametersCount() == 0 && !isThisCall && !elementToWorkWith.isEmpty()) { (elementToWorkWith.getParent() as? JetSecondaryConstructor)?.getColon()?.delete() elementToWorkWith.replace(psiFactory.createConstructorDelegationCall("")) }