Minor, Rename isEmpty -> isImplicit
This commit is contained in:
@@ -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.isEmpty()) {
|
||||
if (element.isImplicit()) {
|
||||
val constructor = element.getStrictParentOfType<JetSecondaryConstructor>()!!
|
||||
val valueParameterList = constructor.getValueParameterList() ?: return markElement(constructor)
|
||||
return markRange(constructor.getConstructorKeyword(), valueParameterList.getLastChild())
|
||||
|
||||
@@ -65,7 +65,7 @@ public class JetConstructorDelegationCall extends JetElementImpl implements JetC
|
||||
return findChildByClass(JetConstructorDelegationReferenceExpression.class);
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
public boolean isImplicit() {
|
||||
JetConstructorDelegationReferenceExpression callee = getCalleeExpression();
|
||||
return callee != null && callee.getFirstChild() == null;
|
||||
}
|
||||
|
||||
@@ -177,9 +177,8 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
|
||||
return findChildByClass(JetConstructorDelegationCall.class);
|
||||
}
|
||||
|
||||
public boolean hasEmptyDelegationCall() {
|
||||
JetConstructorDelegationCall call = getDelegationCall();
|
||||
return call.isEmpty();
|
||||
public boolean hasImplicitDelegationCall() {
|
||||
return getDelegationCall().isImplicit();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -188,12 +187,12 @@ public class JetSecondaryConstructor extends JetDeclarationStub<KotlinPlaceHolde
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetConstructorDelegationCall replaceEmptyDelegationCallWithExplicit(boolean isThis) {
|
||||
public JetConstructorDelegationCall replaceImplicitDelegationCallWithExplicit(boolean isThis) {
|
||||
JetPsiFactory psiFactory = new JetPsiFactory(getProject());
|
||||
JetConstructorDelegationCall current = getDelegationCall();
|
||||
|
||||
assert current.isEmpty()
|
||||
: "Method should not be called with non-existing or non-empty delegation call: " + getText();
|
||||
assert current.isImplicit()
|
||||
: "Method should not be called with explicit delegation call: " + getText();
|
||||
current.delete();
|
||||
|
||||
PsiElement colon = addAfter(psiFactory.createColon(), getValueParameterList());
|
||||
|
||||
@@ -315,7 +315,7 @@ public class CallResolver {
|
||||
|
||||
if (call.getCalleeExpression() == null) return checkArgumentTypesAndFail(context);
|
||||
|
||||
if (constructorDescriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS && call.isEmpty()) {
|
||||
if (constructorDescriptor.getContainingDeclaration().getKind() == ClassKind.ENUM_CLASS && call.isImplicit()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -374,8 +374,8 @@ public class CallResolver {
|
||||
knownTypeParametersSubstitutor));
|
||||
}
|
||||
|
||||
TracingStrategy tracing = call.isEmpty() ?
|
||||
new TracingStrategyForEmptyConstructorDelegationCall(call, context.call) :
|
||||
TracingStrategy tracing = call.isImplicit() ?
|
||||
new TracingStrategyForImplicitConstructorDelegationCall(call, context.call) :
|
||||
TracingStrategyImpl.create(calleeExpression, context.call);
|
||||
|
||||
return computeTasksFromCandidatesAndResolvedCall(context, candidates, CallTransformer.FUNCTION_CALL_TRANSFORMER, tracing);
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.types.ErrorUtils
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
|
||||
|
||||
public class TracingStrategyForEmptyConstructorDelegationCall(
|
||||
public class TracingStrategyForImplicitConstructorDelegationCall(
|
||||
val delegationCall: JetConstructorDelegationCall, call: Call
|
||||
) : AbstractTracingStrategy(delegationCall.getCalleeExpression()!!, call) {
|
||||
|
||||
@@ -40,7 +40,7 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: JetSecon
|
||||
private val keywordToUse = if (isThis) "this" else "super"
|
||||
|
||||
override fun invoke(project: Project, editor: Editor?, file: JetFile?) {
|
||||
val newDelegationCall = element.replaceEmptyDelegationCallWithExplicit(isThis)
|
||||
val newDelegationCall = element.replaceImplicitDelegationCallWithExplicit(isThis)
|
||||
|
||||
val context = element.analyzeFully()
|
||||
val resolvedCall = newDelegationCall.getResolvedCall(context)
|
||||
@@ -55,14 +55,14 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: JetSecon
|
||||
}
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor?, file: PsiFile?): Boolean {
|
||||
return super.isAvailable(project, editor, file) && element.hasEmptyDelegationCall()
|
||||
return super.isAvailable(project, editor, file) && element.hasImplicitDelegationCall()
|
||||
}
|
||||
|
||||
object InsertThisDelegationCallFactory : JetSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val secondaryConstructor = diagnostic.getPsiElement().getNonStrictParentOfType<JetSecondaryConstructor>() ?: return null
|
||||
if (secondaryConstructor.getClassOrObject().getConstructorsCount() <= 1 ||
|
||||
!secondaryConstructor.hasEmptyDelegationCall()) return null
|
||||
!secondaryConstructor.hasImplicitDelegationCall()) return null
|
||||
|
||||
return InsertDelegationCallQuickfix(isThis = true, element = secondaryConstructor)
|
||||
}
|
||||
@@ -73,7 +73,7 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: JetSecon
|
||||
object InsertSuperDelegationCallFactory : JetSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val secondaryConstructor = diagnostic.getPsiElement().getNonStrictParentOfType<JetSecondaryConstructor>() ?: return null
|
||||
if (!secondaryConstructor.hasEmptyDelegationCall()) return null
|
||||
if (!secondaryConstructor.hasImplicitDelegationCall()) return null
|
||||
val klass = secondaryConstructor.getClassOrObject() as? JetClass ?: return null
|
||||
if (klass.hasPrimaryConstructor()) return null
|
||||
|
||||
|
||||
+3
-3
@@ -29,15 +29,15 @@ public class JetConstructorDelegationCallUsage(call: JetConstructorDelegationCal
|
||||
val isThisCall = element.isCallToThis()
|
||||
|
||||
var elementToWorkWith = element
|
||||
if (changeInfo.getNewParametersCount() > 0 && element.isEmpty()) {
|
||||
if (changeInfo.getNewParametersCount() > 0 && element.isImplicit()) {
|
||||
val constructor = element.getParent() as JetSecondaryConstructor
|
||||
elementToWorkWith = constructor.replaceEmptyDelegationCallWithExplicit(isThisCall)
|
||||
elementToWorkWith = constructor.replaceImplicitDelegationCallWithExplicit(isThisCall)
|
||||
}
|
||||
|
||||
val result = JetFunctionCallUsage(
|
||||
elementToWorkWith, changeInfo.methodDescriptor.originalPrimaryFunction).processUsage(changeInfo, elementToWorkWith)
|
||||
|
||||
if (changeInfo.getNewParametersCount() == 0 && !isThisCall && !elementToWorkWith.isEmpty()) {
|
||||
if (changeInfo.getNewParametersCount() == 0 && !isThisCall && !elementToWorkWith.isImplicit()) {
|
||||
(elementToWorkWith.getParent() as? JetSecondaryConstructor)?.getColon()?.delete()
|
||||
elementToWorkWith.replace(JetPsiFactory(element).createConstructorDelegationCall(""))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user