| 382 | } |
| 383 | |
| 384 | QString makeSignatureString(const KDevelop::Declaration* functionDecl, const Signature& signature, const bool editingDefinition) |
| 385 | { |
| 386 | if (!functionDecl || !functionDecl->internalContext()) { |
| 387 | return {}; |
| 388 | } |
| 389 | const auto visibilityFrom = functionDecl->internalContext()->parentContext(); |
| 390 | if (!visibilityFrom) { |
| 391 | return {}; |
| 392 | } |
| 393 | |
| 394 | QString ret; |
| 395 | |
| 396 | if (!editingDefinition) { |
| 397 | auto classMember = dynamic_cast<const ClassMemberDeclaration*>(functionDecl); |
| 398 | if (classMember && classMember->isStatic()) { |
| 399 | ret += QLatin1String("static "); |
| 400 | } |
| 401 | } |
| 402 | |
| 403 | // constructors don't have a return type |
| 404 | if (signature.returnType.isValid()) { |
| 405 | ret += CodegenHelper::simplifiedTypeString(signature.returnType.abstractType(), |
| 406 | visibilityFrom) |
| 407 | + QLatin1Char(' '); |
| 408 | } |
| 409 | |
| 410 | ret += editingDefinition ? functionDecl->qualifiedIdentifier().toString() : functionDecl->identifier().toString(); |
| 411 | int pos = 0; |
| 412 | |
| 413 | QStringList parameters; |
| 414 | parameters.reserve(signature.parameters.size()); |
| 415 | for (const ParameterItem& item : signature.parameters) { |
| 416 | QString parameter; |
| 417 | AbstractType::Ptr type = item.first.abstractType(); |
| 418 | |
| 419 | QString arrayAppendix; |
| 420 | while (auto arrayType = type.dynamicCast<ArrayType>()) { |
| 421 | type = arrayType->elementType(); |
| 422 | //note: we have to prepend since we iterate from outside, i.e. from right to left. |
| 423 | if (arrayType->dimension()) { |
| 424 | arrayAppendix.prepend(QStringLiteral("[%1]").arg(arrayType->dimension())); |
| 425 | } else { |
| 426 | // dimensionless |
| 427 | arrayAppendix.prepend(QLatin1String("[]")); |
| 428 | } |
| 429 | } |
| 430 | parameter += CodegenHelper::simplifiedTypeString(type, visibilityFrom); |
| 431 | |
| 432 | if (!item.second.isEmpty()) { |
| 433 | parameter += QLatin1Char(' ') + item.second; |
| 434 | } |
| 435 | parameter += arrayAppendix; |
| 436 | if (signature.defaultParams.size() > pos && !signature.defaultParams[pos].isEmpty()) { |
| 437 | parameter += QLatin1String(" = ") + signature.defaultParams[pos]; |
| 438 | } |
| 439 | parameters.append(parameter); |
| 440 | ++pos; |
| 441 | } |
no test coverage detected