Change contract of getDelegationCall to @NotNull
Its existence guaranteed by parser
This commit is contained in:
@@ -1441,8 +1441,7 @@ public class JetControlFlowProcessor {
|
|||||||
processParameters(constructor.getValueParameters());
|
processParameters(constructor.getValueParameters());
|
||||||
generateCallOrMarkUnresolved(constructor.getDelegationCall());
|
generateCallOrMarkUnresolved(constructor.getDelegationCall());
|
||||||
|
|
||||||
if (constructor.getDelegationCall() != null && !constructor.getDelegationCall().isCallToThis()
|
if (!constructor.getDelegationCall().isCallToThis()) {
|
||||||
) {
|
|
||||||
generateClassOrObjectInitializers(classOrObject);
|
generateClassOrObjectInitializers(classOrObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -363,7 +363,7 @@ public class JetPsiFactory(private val project: Project) {
|
|||||||
|
|
||||||
public fun createConstructorDelegationCall(text: String): JetConstructorDelegationCall {
|
public fun createConstructorDelegationCall(text: String): JetConstructorDelegationCall {
|
||||||
val colonOrEmpty = if (text.isEmpty()) "" else ": "
|
val colonOrEmpty = if (text.isEmpty()) "" else ": "
|
||||||
return createClass("class A { constructor()$colonOrEmpty$text {}").getSecondaryConstructors().first().getDelegationCall()!!
|
return createClass("class A { constructor()$colonOrEmpty$text {}").getSecondaryConstructors().first().getDelegationCall()
|
||||||
}
|
}
|
||||||
|
|
||||||
public inner class IfChainBuilder() {
|
public inner class IfChainBuilder() {
|
||||||
|
|||||||
@@ -172,14 +172,14 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
|
|||||||
throw new IncorrectOperationException("setName to constructor");
|
throw new IncorrectOperationException("setName to constructor");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@NotNull
|
||||||
public JetConstructorDelegationCall getDelegationCall() {
|
public JetConstructorDelegationCall getDelegationCall() {
|
||||||
return findChildByClass(JetConstructorDelegationCall.class);
|
return findChildByClass(JetConstructorDelegationCall.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasEmptyDelegationCall() {
|
public boolean hasEmptyDelegationCall() {
|
||||||
JetConstructorDelegationCall call = getDelegationCall();
|
JetConstructorDelegationCall call = getDelegationCall();
|
||||||
return call != null && call.isEmpty();
|
return call.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -192,7 +192,7 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
|
|||||||
JetPsiFactory psiFactory = new JetPsiFactory(getProject());
|
JetPsiFactory psiFactory = new JetPsiFactory(getProject());
|
||||||
JetConstructorDelegationCall current = getDelegationCall();
|
JetConstructorDelegationCall current = getDelegationCall();
|
||||||
|
|
||||||
assert current != null && current.isEmpty()
|
assert current.isEmpty()
|
||||||
: "Method should not be called with non-existing or non-empty delegation call: " + getText();
|
: "Method should not be called with non-existing or non-empty delegation call: " + getText();
|
||||||
current.delete();
|
current.delete();
|
||||||
|
|
||||||
|
|||||||
@@ -217,7 +217,8 @@ public class BodyResolver {
|
|||||||
PsiElement constructorToReport = DescriptorToSourceUtils.descriptorToDeclaration(currentConstructor);
|
PsiElement constructorToReport = DescriptorToSourceUtils.descriptorToDeclaration(currentConstructor);
|
||||||
if (constructorToReport != null) {
|
if (constructorToReport != null) {
|
||||||
JetConstructorDelegationCall call = ((JetSecondaryConstructor) constructorToReport).getDelegationCall();
|
JetConstructorDelegationCall call = ((JetSecondaryConstructor) constructorToReport).getDelegationCall();
|
||||||
assert call != null && call.getCalleeExpression() != null : "resolved call and it's callee can't be null";
|
assert call.getCalleeExpression() != null
|
||||||
|
: "Callee expression of delegation call should not be null on cycle as there should be explicit 'this' calls";
|
||||||
trace.report(CYCLIC_CONSTRUCTOR_DELEGATION_CALL.on(call.getCalleeExpression()));
|
trace.report(CYCLIC_CONSTRUCTOR_DELEGATION_CALL.on(call.getCalleeExpression()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -301,11 +301,10 @@ public class CallResolver {
|
|||||||
public OverloadResolutionResults<FunctionDescriptor> resolveConstructorDelegationCall(
|
public OverloadResolutionResults<FunctionDescriptor> resolveConstructorDelegationCall(
|
||||||
@NotNull BindingTrace trace, @NotNull JetScope scope, @NotNull DataFlowInfo dataFlowInfo,
|
@NotNull BindingTrace trace, @NotNull JetScope scope, @NotNull DataFlowInfo dataFlowInfo,
|
||||||
@NotNull ConstructorDescriptor constructorDescriptor,
|
@NotNull ConstructorDescriptor constructorDescriptor,
|
||||||
@Nullable JetConstructorDelegationCall call
|
@NotNull JetConstructorDelegationCall call
|
||||||
) {
|
) {
|
||||||
// Returns `null` when there is nothing to resolve in trivial cases like `null` call expression or
|
// Method returns `null` when there is nothing to resolve in trivial cases like `null` call expression or
|
||||||
// when super call should be conventional enum constructor and super call should be empty
|
// when super call should be conventional enum constructor and super call should be empty
|
||||||
if (call == null) return null;
|
|
||||||
|
|
||||||
BasicCallResolutionContext context = BasicCallResolutionContext.create(
|
BasicCallResolutionContext context = BasicCallResolutionContext.create(
|
||||||
trace, scope,
|
trace, scope,
|
||||||
|
|||||||
@@ -157,9 +157,9 @@ private fun processClassDelegationCallsToSpecifiedConstructor(
|
|||||||
klass: JetClass, constructor: DeclarationDescriptor, process: (JetConstructorDelegationCall) -> Unit
|
klass: JetClass, constructor: DeclarationDescriptor, process: (JetConstructorDelegationCall) -> Unit
|
||||||
) {
|
) {
|
||||||
for (secondaryConstructor in klass.getSecondaryConstructors()) {
|
for (secondaryConstructor in klass.getSecondaryConstructors()) {
|
||||||
val delegationCallDescriptor = secondaryConstructor.getDelegationCall()?.getConstructorCallDescriptor()
|
val delegationCallDescriptor = secondaryConstructor.getDelegationCall().getConstructorCallDescriptor()
|
||||||
if (constructor == delegationCallDescriptor) {
|
if (constructor == delegationCallDescriptor) {
|
||||||
process(secondaryConstructor.getDelegationCall()!!)
|
process(secondaryConstructor.getDelegationCall())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user