1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #ifndef LO_CLANG_SHARED_PLUGINS
15 /** Look for appending result of adding OUString/OString to OUStringBuffer
19 class StringBuffer
: public loplugin::FilteringPlugin
<StringBuffer
>
22 explicit StringBuffer(loplugin::InstantiationData
const& rData
)
23 : FilteringPlugin(rData
)
27 bool preRun() override
29 StringRef
fn(handler
.getMainFileName());
30 return !loplugin::hasPathnamePrefix(fn
, SRCDIR
"/sal/qa/");
37 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
41 bool VisitCXXMemberCallExpr(CXXMemberCallExpr
const*);
44 bool StringBuffer::VisitCXXMemberCallExpr(CXXMemberCallExpr
const* memberCallExpr
)
46 if (ignoreLocation(memberCallExpr
))
48 if (!loplugin::DeclCheck(memberCallExpr
->getRecordDecl())
49 .Class("OUStringBuffer")
53 if (!memberCallExpr
->getMethodDecl()->getIdentifier())
55 if (memberCallExpr
->getMethodDecl()->getName() != "append")
57 auto matTemp
= dyn_cast
<MaterializeTemporaryExpr
>(memberCallExpr
->getArg(0));
60 if (!isa
<CXXOperatorCallExpr
>(matTemp
->GetTemporaryExpr()))
62 report(DiagnosticsEngine::Warning
,
63 "appending added result of OUString to OUStringBuffer, rather do .append(x).append(y)",
64 compat::getBeginLoc(memberCallExpr
))
65 << memberCallExpr
->getSourceRange();
69 loplugin::Plugin::Registration
<StringBuffer
> stringbuffer("stringbuffer", false);
73 #endif // LO_CLANG_SHARED_PLUGINS
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */