namespace
{ class ImplInheritanceHelper : public loplugin::FilteringPlugin<ImplInheritanceHelper>
{ public: explicit ImplInheritanceHelper(loplugin::InstantiationData const& data)
: FilteringPlugin(data)
{
}
virtualbool preRun() override { returntrue; }
virtualvoid run() override
{ if (preRun())
TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
}
bool VisitCXXRecordDecl(const CXXRecordDecl*);
};
bool ImplInheritanceHelper::VisitCXXRecordDecl(const CXXRecordDecl* cxxRecordDecl)
{ if (ignoreLocation(cxxRecordDecl)) returntrue; if (!cxxRecordDecl->isThisDeclarationADefinition()) returntrue; if (cxxRecordDecl->isDependentContext()) returntrue;
// ignore the utility template classes
SourceLocation spellingLocation
= compiler.getSourceManager().getSpellingLoc(cxxRecordDecl->getBeginLoc());
StringRef fileName = getFilenameOfLocation(spellingLocation); if (loplugin::hasPathnamePrefix(fileName, SRCDIR "/include/cppu")) returntrue; if (loplugin::isSamePathname(fileName, SRCDIR "/include/comphelper/compbase.hxx")) returntrue;
// not sure why this extends XPropertyState but does not support it in queryInterface. if (loplugin::DeclCheck(cxxRecordDecl)
.Class("ChainablePropertySet")
.Namespace("comphelper")
.GlobalNamespace()) returntrue; // in these cases the UNO interface is optional if (loplugin::DeclCheck(cxxRecordDecl).Class("OFSInputStreamContainer").GlobalNamespace()) returntrue; if (loplugin::DeclCheck(cxxRecordDecl)
.Class("OPropertyBrowserController")
.Namespace("pcr")
.GlobalNamespace()) returntrue; if (loplugin::DeclCheck(cxxRecordDecl).Class("SdDrawPage").GlobalNamespace()) returntrue; if (loplugin::DeclCheck(cxxRecordDecl).Class("SdMasterPage").GlobalNamespace()) returntrue;
// check if this class extends cppu::WeakImplHelper if (!loplugin::isDerivedFrom(cxxRecordDecl, [](Decl const* decl) -> bool { returnbool(loplugin::DeclCheck(decl)
.Class("WeakImplHelper")
.Namespace("cppu")
.GlobalNamespace());
})) returntrue; // check if this class directly inherits from a UNO interface class bool foundOne = false; for (autoconst& i : cxxRecordDecl->bases())
{ auto rt = i.getType()->getAs<RecordType>(); if (!rt) continue; autoconst bd = cast<CXXRecordDecl>(rt->getDecl())->getDefinition(); auto ctx = bd->getDeclContext(); if (!ctx->isNamespace()) break; auto ns = dyn_cast<NamespaceDecl>(ctx); while (ns)
{ if (ns->getIdentifier() && ns->getName() == "star")
{
foundOne = true; break;
}
ns = dyn_cast_or_null<NamespaceDecl>(ns->getParent());
}
} if (!foundOne) returntrue;
report(DiagnosticsEngine::Warning, "can probably use ImplInheritanceHelper here",
cxxRecordDecl->getLocation())
<< cxxRecordDecl->getSourceRange(); returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.