Render annotations in suspend functions in single modifier list (KT-20185)

#KT-20185 Fixed
This commit is contained in:
Nikolay Krasko
2017-09-13 12:57:19 +03:00
parent d20af1133a
commit b9872b7651
3 changed files with 45 additions and 8 deletions
@@ -309,22 +309,29 @@ internal class DescriptorRendererImpl(
}
val hasAnnotations = length != lengthBefore
val isSuspend = type.isSuspendFunctionType
val isNullable = type.isMarkedNullable
val receiverType = type.getReceiverTypeFromFunctionType()
val needParenthesis = isNullable || (hasAnnotations && receiverType != null)
if (needParenthesis) {
if (isSuspend) {
insert(lengthBefore, '(')
}
else {
if (hasAnnotations) {
assert(last() == ' ')
if (get(lastIndex - 1) != ')') {
// last annotation rendered without parenthesis - need to add them otherwise parsing will be incorrect
insert(lastIndex, "()")
}
}
if (needParenthesis && hasAnnotations) {
assert(last() == ' ')
if (get(lastIndex - 1) != ')') {
// last annotation rendered without parenthesis - need to add them otherwise parsing will be incorrect
insert(lastIndex, "()")
append("(")
}
}
if (needParenthesis) append("(")
renderModifier(this, type.isSuspendFunctionType, "suspend")
renderModifier(this, isSuspend, "suspend")
if (receiverType != null) {
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable ||