Minor, Rename isEmpty -> isImplicit

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