/* SPDX-FileCopyrightText: 2016 Sergio Martins SPDX-FileCopyrightText: 2023 Alexander Lohnau SPDX-License-Identifier: LGPL-2.0-or-later */ #include "qfileinfo-exists.h" #include "HierarchyUtils.h" #include "StringUtils.h" #include #include #include #include #include using namespace clang; void QFileInfoExists::VisitStmt(clang::Stmt *stmt) { auto *existsCall = dyn_cast(stmt); std::string methodName = clazy::qualifiedMethodName(existsCall); if (methodName != "QFileInfo::exists") { return; } auto *ctorExpr = clazy::getFirstChildOfType(existsCall); if (!ctorExpr || clazy::simpleArgTypeName(ctorExpr->getConstructor(), 0, lo()) != "QString") { return; } std::string userArgText = Lexer::getSourceText(CharSourceRange::getTokenRange(ctorExpr->getArg(0)->getSourceRange()), sm(), lo()).str(); emitWarning(stmt->getBeginLoc(), "Use the static QFileInfo::exists() instead. It's documented to be faster.", {clang::FixItHint::CreateReplacement(stmt->getSourceRange(), "QFileInfo::exists(" + userArgText + ")")}); }