in src/checks/level0/fully-qualified-moc-types.cpp [38:92]
void FullyQualifiedMocTypes::VisitDecl(clang::Decl *decl)
{
auto *method = dyn_cast<CXXMethodDecl>(decl);
if (!method) {
return;
}
const AccessSpecifierManager *accessSpecifierManager = m_context->accessSpecifierManager;
if (!accessSpecifierManager) {
return;
}
if (handleQ_PROPERTY(method)) {
return;
}
if (method->isThisDeclarationADefinition() && !method->hasInlineBody()) {
return;
}
QtAccessSpecifierType qst = accessSpecifierManager->qtAccessSpecifierType(method);
if (qst != QtAccessSpecifier_Signal && qst != QtAccessSpecifier_Slot && qst != QtAccessSpecifier_Invokable) {
return;
}
std::string qualifiedTypeName;
std::string typeName;
for (auto *param : method->parameters()) {
QualType t = clazy::pointeeQualType(param->getType());
if (!typeIsFullyQualified(t, /*by-ref*/ qualifiedTypeName, /*by-ref*/ typeName)) {
SourceRange fixitRange = param->getTypeSourceInfo()->getTypeLoc().getSourceRange();
// We don't want to include the & or * characters for the fixit range
if (param->getType()->isReferenceType() || param->getType()->isPointerType()) {
fixitRange = SourceRange(fixitRange.getBegin(), fixitRange.getEnd().getLocWithOffset(-1));
}
std::vector fixits{FixItHint::CreateReplacement(fixitRange, qualifiedTypeName)};
std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " arguments need to be fully-qualified";
emitWarning(param->getTypeSpecStartLoc(), warning, fixits);
}
}
if (qst == QtAccessSpecifier_Slot || qst == QtAccessSpecifier_Invokable) {
QualType returnT = clazy::pointeeQualType(method->getReturnType());
if (!typeIsFullyQualified(returnT, /*by-ref*/ qualifiedTypeName, /*by-ref*/ typeName)) {
SourceRange returnTypeSourceRange = method->getReturnTypeSourceRange();
// We don't want to include the & or * characters for the fixit range
if (method->getReturnType()->isReferenceType() || method->getReturnType()->isPointerType()) {
returnTypeSourceRange = SourceRange(returnTypeSourceRange.getBegin(), returnTypeSourceRange.getEnd().getLocWithOffset(-1));
}
std::string warning = accessSpecifierManager->qtAccessSpecifierTypeStr(qst).str() + " return types need to be fully-qualified";
std::vector fixits{FixItHint::CreateReplacement(returnTypeSourceRange, qualifiedTypeName)};
emitWarning(returnTypeSourceRange.getBegin(), warning, fixits);
}
}
}