* Construct viable forward declarations for the type name. */
| 407 | * Construct viable forward declarations for the type name. |
| 408 | */ |
| 409 | ClangFixits forwardDeclarations(const QVector<Declaration*>& matchingDeclarations, const Path& source) |
| 410 | { |
| 411 | DUChainReadLocker lock; |
| 412 | ClangFixits fixits; |
| 413 | for (const auto decl : matchingDeclarations) { |
| 414 | const auto qid = decl->qualifiedIdentifier(); |
| 415 | |
| 416 | if (qid.count() > 1) { |
| 417 | // TODO: Currently we're not able to determine what is namespaces, class names etc |
| 418 | // and makes a suitable forward declaration, so just suggest "vanilla" declarations. |
| 419 | continue; |
| 420 | } |
| 421 | |
| 422 | const auto range = forwardDeclarationPosition(qid, source); |
| 423 | if (!range.isValid()) { |
| 424 | continue; // do not know where to insert |
| 425 | } |
| 426 | |
| 427 | if (const auto classDecl = dynamic_cast<ClassDeclaration*>(decl)) { |
| 428 | const auto name = qid.last().toString(); |
| 429 | |
| 430 | switch (classDecl->classType()) { |
| 431 | case ClassDeclarationData::Class: |
| 432 | fixits += { |
| 433 | QLatin1String("class ") + name + QLatin1String(";\n"), range, |
| 434 | i18n("Forward declare as 'class'"), |
| 435 | QString() |
| 436 | }; |
| 437 | break; |
| 438 | case ClassDeclarationData::Struct: |
| 439 | fixits += { |
| 440 | QLatin1String("struct ") + name + QLatin1String(";\n"), range, |
| 441 | i18n("Forward declare as 'struct'"), |
| 442 | QString() |
| 443 | }; |
| 444 | break; |
| 445 | default: |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | return fixits; |
| 451 | } |
| 452 | |
| 453 | /** |
| 454 | * Search the persistent symbol table for matching declarations for identifiers @p identifiers |
no test coverage detected