in src/checks/manuallevel/qt6-deprecated-api-fixes.cpp [317:371]
void Qt6DeprecatedAPIFixes::VisitDecl(clang::Decl *decl)
{
auto *funcDecl = decl->getAsFunction();
auto *varDecl = dyn_cast<VarDecl>(decl);
auto *fieldDecl = dyn_cast<FieldDecl>(decl);
if (!funcDecl && !varDecl && !fieldDecl) {
return;
}
DeclaratorDecl *declaratorDecl = nullptr;
QualType qualType;
if (funcDecl) {
declaratorDecl = funcDecl;
qualType = funcDecl->getReturnType();
} else if (varDecl) {
declaratorDecl = varDecl;
qualType = varDecl->getType();
} else if (fieldDecl) {
declaratorDecl = fieldDecl;
qualType = fieldDecl->getType();
}
std::string message;
if (!getMessageForDeclWarning(qualType.getAsString(), message)) {
return;
}
std::vector<FixItHint> fixits;
const std::string type = qualType.getAsString();
if (clazy::endsWith(type, "QString::SplitBehavior")) {
bool isQtNamespaceExplicit = false;
DeclContext *newcontext = clazy::contextForDecl(m_context->lastDecl);
while (newcontext) {
if (clang::isa<NamespaceDecl>(newcontext)) {
auto *namesdecl = dyn_cast<clang::NamespaceDecl>(newcontext);
if (namesdecl->getNameAsString() == "Qt") {
isQtNamespaceExplicit = true;
}
}
newcontext = newcontext->getParent();
}
std::string replacement;
if (!isQtNamespaceExplicit) {
replacement = "Qt::";
}
replacement += "SplitBehavior";
SourceRange sourceRange(declaratorDecl->getTypeSpecStartLoc(), declaratorDecl->getTypeSpecEndLoc());
fixits.push_back(FixItHint::CreateReplacement(sourceRange, replacement));
}
emitWarning(decl->getBeginLoc(), message, fixits);
return;
}