Minor, move isEmpty, isCallToThis to JetConstructorDelegationCall

This commit is contained in:
Denis Zharkov
2015-03-23 12:05:36 +03:00
parent 023e1a13a9
commit 555f9e7c06
6 changed files with 17 additions and 14 deletions
@@ -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);
}
@@ -418,7 +418,7 @@ public object PositioningStrategies {
public val SECONDARY_CONSTRUCTOR_DELEGATION_CALL: PositioningStrategy<JetConstructorDelegationCall> =
object : PositioningStrategy<JetConstructorDelegationCall>() {
override fun mark(element: JetConstructorDelegationCall): List<TextRange> {
if (element.getCalleeExpression()?.isEmpty() ?: false) {
if (element.isEmpty()) {
val constructor = element.getStrictParentOfType<JetSecondaryConstructor>()!!
return markElement(constructor.getConstructorKeyword())
}
@@ -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();
}
}
@@ -28,8 +28,4 @@ public class JetConstructorDelegationReferenceExpression extends JetExpressionIm
public boolean isThis() {
return findChildByType(JetTokens.THIS_KEYWORD) != null;
}
public boolean isEmpty() {
return getFirstChild() == null;
}
}
@@ -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);
@@ -26,11 +26,11 @@ import org.jetbrains.kotlin.psi.JetSecondaryConstructor
public class JetConstructorDelegationCallUsage(call: JetConstructorDelegationCall) : JetUsageInfo<JetConstructorDelegationCall>(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(""))
}