Change Signature: Represent parameter/receiver types using KotlinTypeInfo

This commit is contained in:
Alexey Sedunov
2015-12-16 14:42:06 +03:00
parent e558581667
commit fd79145b73
21 changed files with 205 additions and 152 deletions
@@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.KtCallElement
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.ValueArgument
@@ -99,7 +98,7 @@ public class AddFunctionParametersFix(
val parameterType = parameters.get(i).type
if (argumentType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(argumentType, parameterType)) {
it.parameters.get(i).currentTypeText = IdeDescriptorRenderers.SOURCE_CODE.renderType(argumentType)
it.parameters.get(i).currentTypeInfo = KotlinTypeInfo(false, argumentType)
typesToShorten.add(argumentType)
}
}
@@ -109,7 +108,7 @@ public class AddFunctionParametersFix(
argument,
validator
)
parameterInfo.originalType?.let { typesToShorten.add(it) }
parameterInfo.originalTypeInfo.type?.let { typesToShorten.add(it) }
if (expression != null) {
parameterInfo.defaultValueForCall = expression
@@ -136,8 +135,8 @@ public class AddFunctionParametersFix(
val name = getNewArgumentName(argument, validator)
val expression = argument.getArgumentExpression()
val type = expression?.let { it.analyze().getType(it) } ?: functionDescriptor.builtIns.nullableAnyType
return KotlinParameterInfo(functionDescriptor, -1, name, type, null, null, KotlinValVar.None, null)
.apply { currentTypeText = IdeDescriptorRenderers.SOURCE_CODE.renderType(type) }
return KotlinParameterInfo(functionDescriptor, -1, name, KotlinTypeInfo(false, null))
.apply { currentTypeInfo = KotlinTypeInfo(false, type) }
}
private fun hasOtherUsages(function: PsiElement): Boolean {
@@ -49,7 +49,7 @@ class ChangeFunctionLiteralSignatureFix private constructor(
descriptor.clearNonReceiverParameters()
for (type in parameterTypes) {
val name = KotlinNameSuggester.suggestNamesByType(type, validator, "param").get(0)
descriptor.addParameter(KotlinParameterInfo(functionDescriptor, -1, name, type, null, null, KotlinValVar.None, null))
descriptor.addParameter(KotlinParameterInfo(functionDescriptor, -1, name, KotlinTypeInfo(false, type)))
}
}
}
@@ -76,7 +76,7 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
val newParam = KotlinParameterInfo(
callableDescriptor = originalDescriptor.baseDescriptor,
name = propertyDescriptor.name.asString(),
type = propertyDescriptor.type,
originalTypeInfo = KotlinTypeInfo(false, propertyDescriptor.type),
valOrVar = element.valOrVarKeyword.toValVar(),
modifierList = element.modifierList,
defaultValueForCall = KtPsiFactory(element.project).createExpression(initializerText)
@@ -135,7 +135,7 @@ object InitializePropertyQuickFixFactory : KotlinIntentionActionsFactory() {
val newParam = KotlinParameterInfo(
callableDescriptor = originalDescriptor.baseDescriptor,
name = KotlinNameSuggester.suggestNameByName(propertyDescriptor.name.asString(), validator),
type = propertyDescriptor.type,
originalTypeInfo = KotlinTypeInfo(false, propertyDescriptor.type),
defaultValueForCall = KtPsiFactory(element.project).createExpression(initializerText)
)
it.addParameter(newParam)
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createVariable
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult
@@ -25,6 +24,7 @@ import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.core.refactoring.canRefactor
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinTypeInfo
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
@@ -61,7 +61,7 @@ public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUs
val parameterInfo = KotlinParameterInfo(
callableDescriptor = functionDescriptor,
name = name,
type = paramType,
originalTypeInfo = KotlinTypeInfo(false, paramType),
defaultValueForCall = argumentExpression
)
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getExp
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getTypeParameters
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.guessTypes
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinTypeInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
@@ -118,7 +119,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<KtSim
context,
KotlinParameterInfo(callableDescriptor = functionDescriptor,
name = element.getReferencedName(),
type = paramType,
originalTypeInfo = KotlinTypeInfo(false, paramType),
valOrVar = valOrVar),
element
)
@@ -93,7 +93,7 @@ public open class CreateParameterFromUsageFix<E : KtElement>(
val paramInfo = KotlinParameterInfo(
callableDescriptor = constructorDescriptor,
name = info.name,
type = paramType,
originalTypeInfo = KotlinTypeInfo(false, paramType),
valOrVar = if (info.writable) KotlinValVar.Var else KotlinValVar.Val
)
@@ -29,6 +29,7 @@ import com.intellij.util.VisibilityUtil
import org.jetbrains.kotlin.asJava.getRepresentativeLightMethod
import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.asJava.unwrapped
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
import org.jetbrains.kotlin.descriptors.Visibilities
@@ -40,7 +41,6 @@ import org.jetbrains.kotlin.idea.project.ProjectStructureUtil
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor.Kind
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallerUsage
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.psi.*
@@ -56,7 +56,7 @@ import java.util.*
public open class KotlinChangeInfo(
val methodDescriptor: KotlinMethodDescriptor,
private var name: String = methodDescriptor.getName(),
var newReturnTypeInfo: KotlinTypeInfo = KotlinTypeInfo(methodDescriptor.baseDescriptor.returnType),
var newReturnTypeInfo: KotlinTypeInfo = KotlinTypeInfo(true, methodDescriptor.baseDescriptor.returnType),
var newVisibility: Visibility = methodDescriptor.getVisibility(),
parameterInfos: List<KotlinParameterInfo> = methodDescriptor.getParameters(),
receiver: KotlinParameterInfo? = methodDescriptor.receiver,
@@ -74,6 +74,7 @@ public open class KotlinChangeInfo(
}
private val originalReturnTypeInfo = methodDescriptor.returnTypeInfo
private val originalReceiverTypeInfo = methodDescriptor.receiver?.originalTypeInfo
var receiverParameterInfo: KotlinParameterInfo? = receiver
set(value: KotlinParameterInfo?) {
@@ -184,10 +185,12 @@ public open class KotlinChangeInfo(
return methodDescriptor.getMethod()
}
override fun isReturnTypeChanged(): Boolean = !newReturnTypeInfo.isEquivalentTo(originalReturnTypeInfo)
fun isReceiverTypeChanged(): Boolean = receiverParameterInfo?.getTypeText() != methodDescriptor.renderOriginalReceiverType()
fun isReceiverTypeChanged(): Boolean {
val receiverInfo = receiverParameterInfo ?: return originalReceiverTypeInfo != null
return originalReceiverTypeInfo == null || !receiverInfo.currentTypeInfo.isEquivalentTo(originalReceiverTypeInfo)
}
override fun getLanguage(): Language = KotlinLanguage.INSTANCE
@@ -255,11 +258,12 @@ public open class KotlinChangeInfo(
if (kind == Kind.FUNCTION) {
receiverParameterInfo?.let {
// TODO: Temporary solution until Change Signature is able to infer actual KotlinType from code fragments instead of using text representation
if (KtPsiFactory(context).createTypeIfPossible(it.currentTypeText)?.typeElement is KtFunctionType) {
buffer.append("(${it.currentTypeText})")
} else {
buffer.append(it.currentTypeText)
val typeInfo = it.currentTypeInfo
if (typeInfo.type != null && KotlinBuiltIns.isExactFunctionType(typeInfo.type)) {
buffer.append("(${typeInfo.render()})")
}
else {
buffer.append(typeInfo.render())
}
buffer.append('.')
}
@@ -300,7 +304,7 @@ public open class KotlinChangeInfo(
}
public fun renderReceiverType(inheritedCallable: KotlinCallableDefinitionUsage<*>): String? {
val receiverTypeText = receiverParameterInfo?.currentTypeText ?: return null
val receiverTypeText = receiverParameterInfo?.currentTypeInfo?.render() ?: return null
val typeSubstitutor = inheritedCallable.typeSubstitutor ?: return receiverTypeText
val currentBaseFunction = inheritedCallable.baseFunction.currentCallableDescriptor ?: return receiverTypeText
return currentBaseFunction.extensionReceiverParameter!!.type.renderTypeWithSubstitution(typeSubstitutor, receiverTypeText, false)
@@ -543,19 +547,19 @@ public fun ChangeInfo.toJetChangeInfo(originalChangeSignatureDescriptor: KotlinM
else -> null
}
with(KotlinParameterInfo(callableDescriptor = functionDescriptor,
originalIndex = oldIndex,
name = info.getName(),
type = if (oldIndex >= 0) originalParameterDescriptors[oldIndex].getType() else currentType,
defaultValueForCall = defaultValueExpr)) {
currentTypeText = IdeDescriptorRenderers.SOURCE_CODE_FOR_TYPE_ARGUMENTS.renderType(currentType)
this
val parameterType = if (oldIndex >= 0) originalParameterDescriptors[oldIndex].getType() else currentType
KotlinParameterInfo(callableDescriptor = functionDescriptor,
originalIndex = oldIndex,
name = info.getName(),
originalTypeInfo = KotlinTypeInfo(false, parameterType),
defaultValueForCall = defaultValueExpr).apply {
currentTypeInfo = KotlinTypeInfo(false, currentType)
}
}
return KotlinChangeInfo(originalChangeSignatureDescriptor,
getNewName(),
KotlinTypeInfo(functionDescriptor.returnType),
KotlinTypeInfo(true, functionDescriptor.returnType),
functionDescriptor.getVisibility(),
newParameters,
null,
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.idea.core.CollectingNameValidator
import org.jetbrains.kotlin.idea.core.KotlinNameSuggester
import org.jetbrains.kotlin.idea.util.getResolutionScope
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtCallableDeclaration
@@ -63,11 +64,14 @@ public class KotlinChangeSignatureData(
parameters = baseDescriptor.getValueParameters()
.mapTo(receiver?.let{ arrayListOf(it) } ?: arrayListOf()) { parameterDescriptor ->
val jetParameter = valueParameters?.get(parameterDescriptor.index)
val parameterType = parameterDescriptor.type
val parameterTypeText = jetParameter?.typeReference?.text
?: IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(parameterType)
KotlinParameterInfo(
callableDescriptor = baseDescriptor,
originalIndex = parameterDescriptor.index,
name = parameterDescriptor.getName().asString(),
type = parameterDescriptor.getType(),
originalTypeInfo = KotlinTypeInfo(false, parameterType, parameterTypeText),
defaultValueForParameter = jetParameter?.getDefaultValue(),
valOrVar = jetParameter?.getValOrVarKeyword().toValVar(),
modifierList = jetParameter?.getModifierList()
@@ -86,7 +90,11 @@ public class KotlinChangeSignatureData(
} ?: CollectingNameValidator(paramNames)
val receiverType = baseDescriptor.getExtensionReceiverParameter()?.getType() ?: return null
val receiverName = KotlinNameSuggester.suggestNamesByType(receiverType, validator, "receiver").first()
return KotlinParameterInfo(callableDescriptor = baseDescriptor, name = receiverName, type = receiverType)
val receiverTypeText = (baseDeclaration as? KtCallableDeclaration)?.receiverTypeReference?.text
?: IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(receiverType)
return KotlinParameterInfo(callableDescriptor = baseDescriptor,
name = receiverName,
originalTypeInfo = KotlinTypeInfo(false, receiverType, receiverTypeText))
}
override val original: KotlinMethodDescriptor
@@ -91,7 +91,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
methodDescriptor: KotlinMethodDescriptor
) : KotlinChangeInfo(methodDescriptor = methodDescriptor,
name = "",
newReturnTypeInfo = KotlinTypeInfo(),
newReturnTypeInfo = KotlinTypeInfo(true),
newVisibility = Visibilities.DEFAULT_VISIBILITY,
parameterInfos = emptyList<KotlinParameterInfo>(),
receiver = null,
@@ -669,7 +669,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
val psiFactory = KtPsiFactory(callable.project)
val tempFile = (callable.containingFile as KtFile).createTempCopy()
val functionWithReceiver = tempFile.findElementAt(callable.textOffset)?.getNonStrictParentOfType<KtNamedFunction>() ?: return
val receiverTypeRef = psiFactory.createType(newReceiverInfo.currentTypeText)
val receiverTypeRef = psiFactory.createType(newReceiverInfo.currentTypeInfo.render())
functionWithReceiver.setReceiverTypeReference(receiverTypeRef)
val newContext = functionWithReceiver.bodyExpression!!.analyze(BodyResolveMode.FULL)
@@ -60,8 +60,13 @@ val KotlinMethodDescriptor.returnTypeInfo: KotlinTypeInfo
val text = (baseDeclaration as? KtCallableDeclaration)?.typeReference?.text
?: type?.let { IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type) }
?: "Unit"
return KotlinTypeInfo(type, text)
return KotlinTypeInfo(true, type, text)
}
fun KotlinMethodDescriptor.renderOriginalReceiverType(): String? =
baseDescriptor.getExtensionReceiverParameter()?.getType()?.let { IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(it) }
val KotlinMethodDescriptor.receiverTypeInfo: KotlinTypeInfo
get() {
val type = baseDescriptor.extensionReceiverParameter?.type
val text = (baseDeclaration as? KtCallableDeclaration)?.receiverTypeReference?.text
?: type?.let { IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(type) }
return KotlinTypeInfo(false, type, text)
}
@@ -26,28 +26,25 @@ import org.jetbrains.kotlin.idea.core.refactoring.quoteIfNeeded
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
import org.jetbrains.kotlin.idea.references.KtReference
import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.types.KotlinType
import java.util.*
public class KotlinParameterInfo @JvmOverloads constructor (
val callableDescriptor: CallableDescriptor,
val originalIndex: Int = -1,
private var name: String,
type: KotlinType? = null,
val originalTypeInfo: KotlinTypeInfo = KotlinTypeInfo(false),
var defaultValueForParameter: KtExpression? = null,
var defaultValueForCall: KtExpression? = null,
var valOrVar: KotlinValVar = KotlinValVar.None,
val modifierList: KtModifierList? = null
): ParameterInfo {
val originalType: KotlinType? = type
var currentTypeText: String = getOldTypeText()
var currentTypeInfo: KotlinTypeInfo = originalTypeInfo
public val defaultValueParameterReferences: Map<PsiReference, DeclarationDescriptor>
@@ -125,8 +122,6 @@ public class KotlinParameterInfo @JvmOverloads constructor (
}
}
private fun getOldTypeText() = originalType?.let { IdeDescriptorRenderers.SOURCE_CODE_SHORT_NAMES_IN_TYPES.renderType(it) } ?: ""
override fun getOldIndex(): Int = originalIndex
public val isNewParameter: Boolean
@@ -140,9 +135,9 @@ public class KotlinParameterInfo @JvmOverloads constructor (
this.name = name ?: ""
}
override fun getTypeText(): String = currentTypeText
override fun getTypeText(): String = currentTypeInfo.render()
public val isTypeChanged: Boolean get() = getOldTypeText() != currentTypeText
public val isTypeChanged: Boolean get() = !currentTypeInfo.isEquivalentTo(originalTypeInfo)
override fun isUseAnySingleVariable(): Boolean = false
@@ -151,10 +146,11 @@ public class KotlinParameterInfo @JvmOverloads constructor (
}
public fun renderType(parameterIndex: Int, inheritedCallable: KotlinCallableDefinitionUsage<*>): String {
val typeSubstitutor = inheritedCallable.typeSubstitutor ?: return currentTypeText
val currentBaseFunction = inheritedCallable.baseFunction.currentCallableDescriptor ?: return currentTypeText
val defaultRendering = currentTypeInfo.render()
val typeSubstitutor = inheritedCallable.typeSubstitutor ?: return defaultRendering
val currentBaseFunction = inheritedCallable.baseFunction.currentCallableDescriptor ?: return defaultRendering
val parameterType = currentBaseFunction.getValueParameters().get(parameterIndex).getType()
return parameterType.renderTypeWithSubstitution(typeSubstitutor, currentTypeText, true)
return parameterType.renderTypeWithSubstitution(typeSubstitutor, defaultRendering, true)
}
public fun getInheritedName(inheritedCallable: KotlinCallableDefinitionUsage<*>): String {
@@ -20,12 +20,12 @@ import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
data class KotlinTypeInfo(val type: KotlinType? = null, val text: String? = null)
data class KotlinTypeInfo(val isCovariant: Boolean, val type: KotlinType? = null, val text: String? = null)
fun KotlinTypeInfo.render(): String {
return when {
text != null -> text
type != null -> IdeDescriptorRenderers.SOURCE_CODE.renderType(type)
type != null -> (if (isCovariant) IdeDescriptorRenderers.SOURCE_CODE else IdeDescriptorRenderers.SOURCE_CODE_FOR_TYPE_ARGUMENTS).renderType(type)
else -> ""
}
}
@@ -23,9 +23,7 @@ import com.intellij.refactoring.changeSignature.ParameterTableModelBase;
import com.intellij.refactoring.changeSignature.ParameterTableModelItemBase;
import com.intellij.util.ui.ColumnInfo;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinMethodDescriptor;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinValVar;
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*;
import org.jetbrains.kotlin.psi.KtExpression;
import org.jetbrains.kotlin.psi.KtPsiFactory;
import org.jetbrains.kotlin.psi.KtPsiFactoryKt;
@@ -48,10 +46,17 @@ public abstract class KotlinCallableParameterTableModel extends ParameterTableMo
@Override
protected ParameterTableModelItemBase<KotlinParameterInfo> createRowItem(@Nullable KotlinParameterInfo parameterInfo) {
if (parameterInfo == null) {
parameterInfo = new KotlinParameterInfo(methodDescriptor.getBaseDescriptor(), -1, "", null, null, null, KotlinValVar.None, null);
parameterInfo = new KotlinParameterInfo(methodDescriptor.getBaseDescriptor(),
-1,
"",
new KotlinTypeInfo(false, null, null),
null,
null,
KotlinValVar.None,
null);
}
KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(project);
PsiCodeFragment paramTypeCodeFragment = psiFactory.createTypeCodeFragment(parameterInfo.getTypeText(), myTypeContext);
PsiCodeFragment paramTypeCodeFragment = psiFactory.createTypeCodeFragment(KotlinTypeInfoKt.render(parameterInfo.getCurrentTypeInfo()), myTypeContext);
KtExpression defaultValueForCall = parameterInfo.getDefaultValueForCall();
PsiCodeFragment defaultValueCodeFragment = psiFactory.createExpressionCodeFragment(
defaultValueForCall != null ? defaultValueForCall.getText() : "",
@@ -94,7 +94,7 @@ public class KotlinChangePropertySignatureDialog(
addComponent(receiverTypeCheckBox)
this@KotlinChangePropertySignatureDialog.receiverTypeCheckBox = receiverTypeCheckBox
val receiverTypeCodeFragment = psiFactory.createTypeCodeFragment(methodDescriptor.renderOriginalReceiverType() ?: "",
val receiverTypeCodeFragment = psiFactory.createTypeCodeFragment(methodDescriptor.receiverTypeInfo.render(),
methodDescriptor.baseDeclaration)
receiverTypeField = EditorTextField(documentManager.getDocument(receiverTypeCodeFragment), myProject, KotlinFileType.INSTANCE)
receiverTypeLabel = JLabel("Receiver type: ")
@@ -142,10 +142,10 @@ public class KotlinChangePropertySignatureDialog(
name = "receiver",
defaultValueForCall = getDefaultReceiverValue())
} else null
receiver?.currentTypeText = receiverTypeField.getText()
receiver?.currentTypeInfo = KotlinTypeInfo(false, null, receiverTypeField.getText())
val changeInfo = KotlinChangeInfo(originalDescriptor,
nameField.getText(),
KotlinTypeInfo(null, returnTypeField.text),
KotlinTypeInfo(true, null, returnTypeField.text),
visibilityCombo.getSelectedItem() as Visibility,
emptyList(),
receiver,
@@ -405,15 +405,15 @@ public class KotlinChangeSignatureDialog(
return KotlinChangeSignatureProcessor(project, changeInfo, commandName)
}
private fun PsiCodeFragment?.getTypeInfo(forPreview: Boolean): KotlinTypeInfo {
if (this !is KtTypeCodeFragment) return KotlinTypeInfo()
private fun PsiCodeFragment?.getTypeInfo(isCovariant: Boolean, forPreview: Boolean): KotlinTypeInfo {
if (this !is KtTypeCodeFragment) return KotlinTypeInfo(isCovariant)
val typeRef = getContentElement()
val type = typeRef?.analyze(BodyResolveMode.PARTIAL)?.get(BindingContext.TYPE, typeRef)
return when {
type != null && !type.isError -> KotlinTypeInfo(type, if (forPreview) typeRef?.text else null)
typeRef != null -> KotlinTypeInfo(null, typeRef.text)
else -> KotlinTypeInfo()
type != null && !type.isError -> KotlinTypeInfo(isCovariant, type, if (forPreview) typeRef?.text else null)
typeRef != null -> KotlinTypeInfo(isCovariant, null, typeRef.text)
else -> KotlinTypeInfo(isCovariant)
}
}
@@ -427,7 +427,7 @@ public class KotlinChangeSignatureDialog(
val parameters = parametersModel.getItems().map { parameter ->
val parameterInfo = parameter.parameter
parameterInfo.currentTypeText = parameter.typeCodeFragment.getTypeInfo(forPreview).render()
parameterInfo.currentTypeInfo = parameter.typeCodeFragment.getTypeInfo(false, forPreview)
val codeFragment = parameter.defaultValueCodeFragment as KtExpressionCodeFragment
val oldDefaultValue = parameterInfo.defaultValueForCall
@@ -440,7 +440,7 @@ public class KotlinChangeSignatureDialog(
return KotlinChangeInfo(methodDescriptor.original,
methodName,
returnTypeCodeFragment.getTypeInfo(forPreview),
returnTypeCodeFragment.getTypeInfo(true, forPreview),
visibility ?: Visibilities.DEFAULT_VISIBILITY,
parameters,
parametersModel.getReceiver(),
@@ -155,7 +155,7 @@ fun IntroduceParameterDescriptor.performRefactoring() {
defaultValueForCall = if (withDefaultValue) null else defaultValue,
defaultValueForParameter = if (withDefaultValue) defaultValue else null,
valOrVar = valVar)
parameterInfo.currentTypeText = newParameterTypeText
parameterInfo.currentTypeInfo = KotlinTypeInfo(false, null, newParameterTypeText)
methodDescriptor.addParameter(parameterInfo)
}
}
@@ -31,17 +31,13 @@ import org.jetbrains.kotlin.idea.caches.resolve.getJavaMethodDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.core.refactoring.dropOverrideKeywordIfNecessary
import org.jetbrains.kotlin.idea.core.refactoring.j2k
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinChangeInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinChangeSignatureData
import org.jetbrains.kotlin.idea.refactoring.changeSignature.KotlinParameterInfo
import org.jetbrains.kotlin.idea.refactoring.changeSignature.originalBaseFunctionDescriptor
import org.jetbrains.kotlin.idea.refactoring.changeSignature.*
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinCallableDefinitionUsage
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinConstructorDelegationCallUsage
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinFunctionCallUsage
import org.jetbrains.kotlin.idea.refactoring.changeSignature.usages.KotlinUsageInfo
import org.jetbrains.kotlin.idea.search.declarationsSearch.HierarchySearchRequest
import org.jetbrains.kotlin.idea.search.declarationsSearch.searchOverriders
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
@@ -71,7 +67,7 @@ public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMe
val defaultValueForCall = (data.getParameterInitializer().getExpression() as? PsiExpression)?.let { it.j2k() }
changeInfo.addParameter(KotlinParameterInfo(callableDescriptor = psiMethodDescriptor,
name = data.getParameterName(),
type = psiMethodDescriptor.builtIns.anyType,
originalTypeInfo = KotlinTypeInfo(false, psiMethodDescriptor.builtIns.anyType),
defaultValueForCall = defaultValueForCall))
return changeInfo
}
@@ -82,7 +78,7 @@ public class KotlinIntroduceParameterMethodUsageProcessor : IntroduceParameterMe
val changeInfo = createChangeInfo(data, element) ?: return true
// Java method is already updated at this point
val addedParameterType = data.getMethodToReplaceIn().getJavaMethodDescriptor()!!.getValueParameters().last().getType()
changeInfo.getNewParameters().last().currentTypeText = IdeDescriptorRenderers.SOURCE_CODE.renderType(addedParameterType)
changeInfo.getNewParameters().last().currentTypeInfo = KotlinTypeInfo(false, addedParameterType)
val scope = element.getUseScope().let {
if (it is GlobalSearchScope) GlobalSearchScope.getScopeRestrictedByFileTypes(it, KotlinFileType.INSTANCE) else it
@@ -2,5 +2,5 @@
// DISABLE-ERRORS
fun main(args: Array<String>) {
Test<String>().perform("") { s: String?, s1: String? -> }
Test<String>().perform("") { s: String, s1: String -> }
}
@@ -1,4 +1,4 @@
// "Create parameter 's'" "true"
// ERROR: Unresolved reference: s
internal fun foo(s: String?) = C(s)
internal fun foo(s: String) = C(s)
@@ -4,9 +4,9 @@ fun test() {
}
abstract class K0 {
abstract fun foo(c: Int, a1: A?): Int
abstract fun foo(c: Int, a1: A): Int
}
open class K: K0() {
override fun foo(c: Int, a1: A?) = a + b + c
override fun foo(c: Int, a1: A) = a + b + c
}
@@ -268,11 +268,11 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testRenameFunction() = doTest { newName = "after" }
fun testChangeReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.floatType) }
fun testChangeReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.floatType) }
fun testAddReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.floatType) }
fun testAddReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.floatType) }
fun testRemoveReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.unitType) }
fun testRemoveReturnType() = doTest { newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.unitType) }
fun testChangeConstructorVisibility() = doTest { newVisibility = Visibilities.PROTECTED }
@@ -282,7 +282,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
val newParameter = KotlinParameterInfo(
callableDescriptor = originalBaseFunctionDescriptor,
name = "x",
type = BUILT_INS.anyType,
originalTypeInfo = KotlinTypeInfo(false, BUILT_INS.anyType),
defaultValueForCall = KtPsiFactory(project).createExpression("12"),
valOrVar = KotlinValVar.Val
)
@@ -300,7 +300,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
newParameters[1].name = "_x2"
newParameters[2].name = "_x3"
newParameters[1].currentTypeText = "Float?"
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.floatType.makeNullable())
}
fun testGenericConstructor() = doTest {
@@ -314,7 +314,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
newParameters[1].name = "_x2"
newParameters[2].name = "_x3"
newParameters[1].currentTypeText = "Double?"
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.doubleType.makeNullable())
}
fun testConstructorSwapArguments() = doTest {
@@ -331,7 +331,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
newParameters[1].name = "_x2"
newParameters[2].name = "_x3"
newParameters[1].currentTypeText = "Float?"
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.floatType.makeNullable())
}
fun testGenericFunctions() = doTest() {
@@ -341,13 +341,13 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
newParameters[1].name = "_x2"
newParameters[2].name = "_x3"
newParameters[1].currentTypeText = "Double?"
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.doubleType.makeNullable())
}
fun testExpressionFunction() = doTest {
newParameters[0].name = "x1"
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "y1", BUILT_INS.intType))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "y1", KotlinTypeInfo(false, BUILT_INS.intType)))
}
fun testFunctionsAddRemoveArguments() = doTest {
@@ -357,18 +357,23 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
val newParameters = newParameters
setNewParameter(2, newParameters[1])
setNewParameter(1, newParameters[0])
setNewParameter(0, KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "x0", BUILT_INS.nullableAnyType, null, defaultValueForCall))
setNewParameter(0, KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"x0",
KotlinTypeInfo(false, BUILT_INS.nullableAnyType),
null,
defaultValueForCall))
}
fun testFakeOverride() = doTest {
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "i", BUILT_INS.intType))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "i", KotlinTypeInfo(false, BUILT_INS.intType)))
}
fun testFunctionLiteral() = doTest {
newParameters[1].name = "y1"
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "x", BUILT_INS.anyType))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "x", KotlinTypeInfo(false, BUILT_INS.anyType)))
newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.intType)
newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.intType)
}
fun testVarargs() = doTestConflict()
@@ -398,58 +403,78 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testNoDefaultValuesInOverrides() = doTest { swapParameters(0, 1) }
fun testOverridesInEnumEntries() = doTest {
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType)))
}
fun testEnumEntriesWithoutSuperCalls() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"n",
KotlinTypeInfo(false, BUILT_INS.intType),
null,
defaultValueForCall))
}
fun testParameterChangeInOverrides() = doTest {
newParameters[0].name = "n"
newParameters[0].currentTypeText = "Int"
newParameters[0].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.intType)
}
fun testConstructorJavaUsages() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"abc\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"s",
KotlinTypeInfo(false, BUILT_INS.stringType),
null,
defaultValueForCall))
}
fun testFunctionJavaUsagesAndOverridesAddParam() = doTest {
val psiFactory = KtPsiFactory(project)
val defaultValueForCall1 = psiFactory.createExpression("\"abc\"")
val defaultValueForCall2 = psiFactory.createExpression("\"def\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall1))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "o", BUILT_INS.nullableAnyType, null, defaultValueForCall2))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"s",
KotlinTypeInfo(false, BUILT_INS.stringType),
null,
defaultValueForCall1))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"o",
KotlinTypeInfo(false, BUILT_INS.nullableAnyType),
null,
defaultValueForCall2))
}
fun testFunctionJavaUsagesAndOverridesChangeNullability() = doTest {
newParameters[1].currentTypeText = "String?"
newParameters[2].currentTypeText = "Any"
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.stringType.makeNullable())
newParameters[2].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.anyType)
newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.stringType.makeNullable())
newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.stringType.makeNullable())
}
fun testFunctionJavaUsagesAndOverridesChangeTypes() = doTest {
newParameters[0].currentTypeText = "String?"
newParameters[1].currentTypeText = "Int"
newParameters[2].currentTypeText = "Long?"
newParameters[0].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.stringType.makeNullable())
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.intType)
newParameters[2].currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.longType.makeNullable())
newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.nullableAnyType)
newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.nullableAnyType)
}
fun testGenericsWithOverrides() = doTest {
newParameters[0].currentTypeText = "List<C>"
newParameters[1].currentTypeText = "A?"
newParameters[2].currentTypeText = "U<B>"
newParameters[0].currentTypeInfo = KotlinTypeInfo(false, null, "List<C>")
newParameters[1].currentTypeInfo = KotlinTypeInfo(false, null, "A?")
newParameters[2].currentTypeInfo = KotlinTypeInfo(false, null, "U<B>")
newReturnTypeInfo = KotlinTypeInfo(null, "U<C>?")
newReturnTypeInfo = KotlinTypeInfo(true, null, "U<C>?")
}
fun testAddReceiverToGenericsWithOverrides() = doTest {
val parameterInfo = newParameters[0]
parameterInfo.currentTypeText = "U<A>"
parameterInfo.currentTypeInfo = KotlinTypeInfo(false, null, "U<A>")
receiverParameterInfo = parameterInfo
}
@@ -487,18 +512,22 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testFunctionRenameJavaUsages() = doTest { newName = "bar" }
fun testParameterModifiers() = doTest { addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType)) }
fun testParameterModifiers() = doTest {
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType)))
}
fun testFqNameShortening() = doTest {
val newParameter = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.anyType).apply {
currentTypeText = "kotlin.String"
val newParameter = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.anyType)).apply {
currentTypeInfo = KotlinTypeInfo(false, null, "kotlin.String")
}
addParameter(newParameter)
}
fun testObjectMember() = doTest { removeParameter(0) }
fun testParameterListAddParam() = doTest { addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "l", BUILT_INS.longType)) }
fun testParameterListAddParam() = doTest {
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "l", KotlinTypeInfo(false, BUILT_INS.longType)))
}
fun testParameterListRemoveParam() = doTest { removeParameter(getNewParametersCount() - 1) }
@@ -506,26 +535,26 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testAddNewReceiver() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("X(0)")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", BUILT_INS.anyType, null, defaultValueForCall)
.apply { currentTypeText = "X" }
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", KotlinTypeInfo(false, BUILT_INS.anyType), null, defaultValueForCall)
.apply { currentTypeInfo = KotlinTypeInfo(false, null, "X") }
}
fun testAddNewReceiverForMember() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("X(0)")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", BUILT_INS.anyType, null, defaultValueForCall)
.apply { currentTypeText = "X" }
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", KotlinTypeInfo(false, BUILT_INS.anyType), null, defaultValueForCall)
.apply { currentTypeInfo = KotlinTypeInfo(false, null, "X") }
}
fun testAddNewReceiverForMemberConflict() = doTestConflict {
val defaultValueForCall = KtPsiFactory(project).createExpression("X(0)")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", BUILT_INS.anyType, null, defaultValueForCall)
.apply { currentTypeText = "X" }
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", KotlinTypeInfo(false, BUILT_INS.anyType), null, defaultValueForCall)
.apply { currentTypeInfo = KotlinTypeInfo(false, null, "X") }
}
fun testAddNewReceiverConflict() = doTestConflict {
val defaultValueForCall = KtPsiFactory(project).createExpression("X(0)")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", BUILT_INS.anyType, null, defaultValueForCall)
.apply { currentTypeText = "X" }
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "_", KotlinTypeInfo(false, BUILT_INS.anyType), null, defaultValueForCall)
.apply { currentTypeInfo = KotlinTypeInfo(false, null, "X") }
}
fun testRemoveReceiver() = doTest { removeParameter(0) }
@@ -573,40 +602,40 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testChangeReceiverForMember() = doTest { receiverParameterInfo = newParameters[1] }
fun testChangeParameterTypeWithImport() = doTest { newParameters[0].currentTypeText = "a.Bar" }
fun testChangeParameterTypeWithImport() = doTest { newParameters[0].currentTypeInfo = KotlinTypeInfo(false, null, "a.Bar") }
fun testSecondaryConstructor() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"foo\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType), null, defaultValueForCall))
}
fun testJavaConstructorInDelegationCall() = doJavaTest { newParameters.add(ParameterInfoImpl(-1, "s", stringPsiType, "\"foo\"")) }
fun testPrimaryConstructorByThisRef() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"foo\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType), null, defaultValueForCall))
}
fun testPrimaryConstructorBySuperRef() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"foo\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType), null, defaultValueForCall))
}
fun testSecondaryConstructorByThisRef() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"foo\"")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType), null, defaultValueForCall))
}
fun testSecondaryConstructorBySuperRef() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"foo\"")
addParameter(KotlinParameterInfo(methodDescriptor.baseDescriptor, -1, "s", BUILT_INS.stringType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(methodDescriptor.baseDescriptor, -1, "s", KotlinTypeInfo(false, BUILT_INS.stringType), null, defaultValueForCall))
}
fun testJavaConstructorBySuperRef() = doJavaTest { newParameters.add(ParameterInfoImpl(-1, "s", stringPsiType, "\"foo\"")) }
fun testNoConflictWithReceiverName() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("0")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "i", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "i", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
}
fun testRemoveParameterBeforeLambda() = doTest { removeParameter(1) }
@@ -644,7 +673,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testPrimaryConstructorByRef() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
}
fun testReceiverToParameterExplicitReceiver() = doTest { receiverParameterInfo = null }
@@ -669,49 +698,59 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testChangeProperty() = doTest {
newName = "s"
newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.stringType)
newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.stringType)
}
fun testAddPropertyReceiverConflict() = doTestConflict {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"\"")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "receiver", BUILT_INS.stringType, null, defaultValueForCall)
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"receiver",
KotlinTypeInfo(false, BUILT_INS.stringType),
null,
defaultValueForCall)
}
fun testAddPropertyReceiver() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("\"\"")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "receiver", BUILT_INS.stringType, null, defaultValueForCall)
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor,
-1,
"receiver",
KotlinTypeInfo(false, BUILT_INS.stringType),
null,
defaultValueForCall)
}
fun testChangePropertyReceiver() = doTest { receiverParameterInfo!!.currentTypeText = "Int" }
fun testChangePropertyReceiver() = doTest { receiverParameterInfo!!.currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.intType) }
fun testRemovePropertyReceiver() = doTest { receiverParameterInfo = null }
fun testAddTopLevelPropertyReceiver() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("A()")
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "receiver", null, null, defaultValueForCall)
.apply { currentTypeText = "test.A" }
receiverParameterInfo = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "receiver", KotlinTypeInfo(false), null, defaultValueForCall)
.apply { currentTypeInfo = KotlinTypeInfo(false, null, "test.A") }
}
fun testChangeTopLevelPropertyReceiver() = doTest { receiverParameterInfo!!.currentTypeText = "String" }
fun testChangeTopLevelPropertyReceiver() = doTest { receiverParameterInfo!!.currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.stringType) }
fun testRemoveTopLevelPropertyReceiver() = doTest { receiverParameterInfo = null }
fun testChangeClassParameter() = doTest {
newName = "s"
newReturnTypeInfo = KotlinTypeInfo(BUILT_INS.stringType)
newReturnTypeInfo = KotlinTypeInfo(true, BUILT_INS.stringType)
}
fun testParameterPropagation() = doTest {
val psiFactory = KtPsiFactory(project)
val defaultValueForCall1 = psiFactory.createExpression("1")
val newParameter1 = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", null, null, defaultValueForCall1)
.apply { currentTypeText = "kotlin.Int" }
val newParameter1 = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false), null, defaultValueForCall1)
.apply { currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.intType) }
addParameter(newParameter1)
val defaultValueForCall2 = psiFactory.createExpression("\"abc\"")
val newParameter2 = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", null, null, defaultValueForCall2)
.apply { currentTypeText = "kotlin.String" }
val newParameter2 = KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "s", KotlinTypeInfo(false), null, defaultValueForCall2)
.apply { currentTypeInfo = KotlinTypeInfo(false, BUILT_INS.stringType) }
addParameter(newParameter2)
val classA = KotlinFullClassNameIndex.getInstance().get("A", project, project.allScope()).first()
@@ -735,21 +774,21 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testPropagateWithParameterDuplication() = doTestConflict {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
primaryPropagationTargets = listOf(KotlinTopLevelFunctionFqnNameIndex.getInstance().get("bar", project, project.allScope()).first())
}
fun testPropagateWithVariableDuplication() = doTestConflict {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
primaryPropagationTargets = listOf(KotlinTopLevelFunctionFqnNameIndex.getInstance().get("bar", project, project.allScope()).first())
}
fun testPropagateWithThisQualificationInClassMember() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
val classA = KotlinFullClassNameIndex.getInstance().get("A", project, project.allScope()).first()
val functionBar = classA.declarations.first { it is KtNamedFunction && it.name == "bar" }
@@ -758,7 +797,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testPropagateWithThisQualificationInExtension() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
primaryPropagationTargets = listOf(KotlinTopLevelFunctionFqnNameIndex.getInstance().get("bar", project, project.allScope()).first())
}
@@ -770,14 +809,14 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testPrimaryConstructorParameterPropagation() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
primaryPropagationTargets = findCallers(method.getRepresentativeLightMethod()!!)
}
fun testSecondaryConstructorParameterPropagation() = doTest {
val defaultValueForCall = KtPsiFactory(project).createExpression("1")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValueForCall))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValueForCall))
primaryPropagationTargets = findCallers(method.getRepresentativeLightMethod()!!)
}
@@ -793,7 +832,7 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
fun testRenameExtensionParameterWithNamedArgs() = doTest { newParameters[2].name = "bb" }
fun testImplicitThisToParameterWithChangedType() = doTest {
receiverParameterInfo!!.currentTypeText = "Older"
receiverParameterInfo!!.currentTypeInfo = KotlinTypeInfo(false, null, "Older")
receiverParameterInfo = null
}
@@ -805,12 +844,12 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
private fun doTestJvmOverloadedAddDefault(index: Int) = doTest {
val defaultValue = KtPsiFactory(project).createExpression("2")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, defaultValue, defaultValue), index)
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), defaultValue, defaultValue), index)
}
private fun doTestJvmOverloadedAddNonDefault(index: Int) = doTest {
val defaultValue = KtPsiFactory(project).createExpression("2")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", BUILT_INS.intType, null, defaultValue), index)
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "n", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValue), index)
}
fun testJvmOverloadedAddDefault1() = doTestJvmOverloadedAddDefault(0)
@@ -847,8 +886,8 @@ class KotlinChangeSignatureTest : KotlinCodeInsightTestCase() {
val psiFactory = KtPsiFactory(project)
val defaultValue1 = psiFactory.createExpression("4")
val defaultValue2 = psiFactory.createExpression("5")
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "d", BUILT_INS.intType, null, defaultValue1), 2)
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "e", BUILT_INS.intType, null, defaultValue2))
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "d", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValue1), 2)
addParameter(KotlinParameterInfo(originalBaseFunctionDescriptor, -1, "e", KotlinTypeInfo(false, BUILT_INS.intType), null, defaultValue2))
}
fun testRemoveParameterKeepFormat1() = doTest { removeParameter(0) }