MCPcopy Create free account
hub / github.com/KDE/kdevelop / forwardDeclarations

Function forwardDeclarations

plugins/clang/duchain/unknowndeclarationproblem.cpp:409–451  ·  view source on GitHub ↗

* Construct viable forward declarations for the type name. */

Source from the content-addressed store, hash-verified

407 * Construct viable forward declarations for the type name.
408 */
409ClangFixits 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

Callers 1

fixUnknownDeclarationFunction · 0.85

Calls 8

classTypeMethod · 0.80
QStringClass · 0.50
qualifiedIdentifierMethod · 0.45
countMethod · 0.45
isValidMethod · 0.45
toStringMethod · 0.45
lastMethod · 0.45

Tested by

no test coverage detected