Change Signature: Parenthesize functional type of receiver in the signature preview
#KT-8737 Fixed
This commit is contained in:
@@ -88,13 +88,18 @@ public class KtPsiFactory(private val project: Project) {
|
||||
}
|
||||
|
||||
public fun createType(type: String): KtTypeReference {
|
||||
val typeReference = createProperty("val x : $type").typeReference
|
||||
val typeReference = createTypeIfPossible(type)
|
||||
if (typeReference == null || typeReference.text != type) {
|
||||
throw IllegalArgumentException("Incorrect type: $type")
|
||||
}
|
||||
return typeReference
|
||||
}
|
||||
|
||||
public fun createTypeIfPossible(type: String): KtTypeReference? {
|
||||
val typeReference = createProperty("val x : $type").typeReference
|
||||
return if (typeReference?.text == type) typeReference else null
|
||||
}
|
||||
|
||||
public fun createStar(): PsiElement {
|
||||
return createType("List<*>").findElementAt(5)!!
|
||||
}
|
||||
|
||||
@@ -247,7 +247,13 @@ public open class KotlinChangeInfo(
|
||||
|
||||
if (kind == Kind.FUNCTION) {
|
||||
receiverParameterInfo?.let {
|
||||
buffer.append(it.currentTypeText).append('.')
|
||||
// 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)
|
||||
}
|
||||
buffer.append('.')
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user