Change Signature: Parenthesize functional type of receiver in the signature preview

#KT-8737 Fixed
This commit is contained in:
Alexey Sedunov
2015-12-03 18:16:15 +03:00
parent 8f8acf7a83
commit d850d7bbad
2 changed files with 13 additions and 2 deletions
@@ -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('.')
}
}