diff --git a/language/duchain/duchainutils.cpp b/language/duchain/duchainutils.cpp --- a/language/duchain/duchainutils.cpp +++ b/language/duchain/duchainutils.cpp @@ -26,6 +26,7 @@ #include #include "../interfaces/ilanguagesupport.h" +#include "types/structuretype.h" #include "util/debug.h" #include "declaration.h" @@ -477,6 +478,25 @@ return ret; } +namespace +{ +bool doesDirectlyInherit(const Declaration* child, const Declaration* base, const TopDUContext* topContext) +{ + const auto childClass = dynamic_cast(child); + if (!childClass) + return false; + + FOREACH_FUNCTION(const BaseClassInstance& baseClass, childClass->baseClasses) { + const auto structureType = baseClass.baseClass.type(); + if (structureType && structureType->declaration(topContext) == base) { + return true; + } + } + + return false; +} +} + ///For a class, returns all classes that inherit it QList DUChainUtils::getInheriters(const Declaration* decl, uint& maxAllowedSteps, bool collectVersions) { @@ -488,15 +508,17 @@ if(maxAllowedSteps == 0) return ret; + const TopDUContext* topContext = decl->topContext(); + if(decl->internalContext() && decl->internalContext()->type() == DUContext::Class) for (const IndexedDUContext& importer : decl->internalContext()->indexedImporters()) { DUContext* imp = importer.data(); if(!imp) continue; - if(imp->type() == DUContext::Class && imp->owner()) + if(imp->type() == DUContext::Class && imp->owner() && doesDirectlyInherit(imp->owner(), decl, topContext)) ret << imp->owner(); --maxAllowedSteps;