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/.
10 #include "clang/Lex/Lexer.h"
17 * Rewrites all Paint method on subclasses of vcl::Window to include RenderContext& as parameter.
19 * run as: make COMPILER_PLUGIN_TOOL=paintmethodconversion UPDATE_FILES=all FORCE_COMPILE=all
25 bool baseCheckNotWindowSubclass(const CXXRecordDecl
* aBaseDefinition
, void* /*pInput*/)
27 if (aBaseDefinition
&& aBaseDefinition
->getQualifiedNameAsString() == "vcl::Window")
34 bool isDerivedFromWindow(const CXXRecordDecl
* decl
) {
38 if (decl
->getQualifiedNameAsString() == "vcl::Window")
40 if (!decl
->forallBases(baseCheckNotWindowSubclass
, nullptr, true))
46 class PaintMethodConversion
: public loplugin::FilteringRewritePlugin
<PaintMethodConversion
>
49 explicit PaintMethodConversion(InstantiationData
const& data
):
50 FilteringRewritePlugin(data
)
53 virtual void run() override
55 TraverseDecl(compiler
.getASTContext().getTranslationUnitDecl());
58 bool TraverseCXXMethodDecl(const CXXMethodDecl
* methodDeclaration
)
63 if (methodDeclaration
->getNameAsString() != "Paint")
66 if (!isDerivedFromWindow(methodDeclaration
->getParent()))
71 unsigned int nNoOfParameters
= methodDeclaration
->getNumParams();
73 if (nNoOfParameters
== 1) // we expect only one parameter Paint(Rect&)
75 const ParmVarDecl
* parameterDecl
= methodDeclaration
->getParamDecl(0);
76 if (methodDeclaration
->hasBody())
78 rewriter
->InsertText(parameterDecl
->getLocStart(), "vcl::RenderContext& /*rRenderContext*/, ", true, true);
82 rewriter
->InsertText(parameterDecl
->getLocStart(), "vcl::RenderContext& rRenderContext, ", true, true);
90 loplugin::Plugin::Registration
<PaintMethodConversion
> X("paintmethodconversion", true);
94 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */